类 RedisUtil

java.lang.Object
cn.openjava.redis.starter.utils.RedisUtil

@Component public class RedisUtil extends Object
  • 构造器详细资料

    • RedisUtil

      public RedisUtil()
  • 方法详细资料

    • set

      public boolean set(String key, String value)
      写入缓存
      参数:
      key - redis键
      value - redis值
      返回:
      是否成功
    • set

      public boolean set(String key, String value, Long expireTime)
      写入缓存设置时效时间
      参数:
      key - redis键
      value - redis值
      返回:
      是否成功
    • removeByKeys

      public void removeByKeys(String... keys)
      批量删除对应的键值对
      参数:
      keys - Redis键名数组
    • removePattern

      public void removePattern(String pattern)
      批量删除Redis key
      参数:
      pattern - 键名包含字符串(如:myKey*)
    • expire

      public boolean expire(Object key, Duration duration)
      过期时间
      参数:
      key - key值
      duration - 时间
      返回:
      是否过期
    • remove

      public void remove(String key)
      删除key,也删除对应的value
      参数:
      key - Redis键名
    • exists

      public Boolean exists(String key)
      判断缓存中是否有对应的value
      参数:
      key - Redis键名
      返回:
      是否存在
    • get

      public String get(String key)
      读取缓存
      参数:
      key - Redis键名
      返回:
      是否存在
    • hmSet

      public void hmSet(String key, String hashKey, String value)
      哈希 添加
      参数:
      key - Redis键
      hashKey - 哈希键
      value - 哈希值
    • hmGet

      public String hmGet(String key, String hashKey)
      哈希获取数据
      参数:
      key - Redis键
      hashKey - 哈希键
      返回:
      哈希值
    • hmHasKey

      public boolean hmHasKey(String key, String hashKey)
      判断hash是否存在键
      参数:
      key - Redis键
      hashKey - 哈希键
      返回:
      是否存在
    • hmRemove

      public long hmRemove(String key, String... hashKeys)
      删除hash中一条或多条数据
      参数:
      key - Redis键
      hashKeys - 哈希键名数组
      返回:
      删除数量
    • hashMapGet

      public Map<String,String> hashMapGet(String key)
      获取所有哈希键值对
      参数:
      key - Redis键名
      返回:
      哈希Map
    • hashMapSet

      public void hashMapSet(String key, Map<String,String> map)
      保存Map到哈希
      参数:
      key - Redis键名
      map - 哈希Map
    • lPush

      public void lPush(String key, String value)
      列表-追加值
      参数:
      key - Redis键名
      value - 列表值
    • lRemove

      public void lRemove(String key, String value)
      列表-删除值
      参数:
      key - Redis键名
      value - 列表值
    • lRange

      public List<String> lRange(String key, long start, long end)
      列表-获取指定范围数据
      参数:
      key - Redis键名
      start - 开始行号(start:0,end:-1查询所有值)
      end - 结束行号
      返回:
      列表
    • add

      public void add(String key, String value)
      集合添加
      参数:
      key - Redis键名
      value - 值
    • setMembers

      public Set<String> setMembers(String key)
      集合获取
      参数:
      key - Redis键名
      返回:
      集合
    • zAdd

      public void zAdd(String key, String value, double score)
      有序集合添加
      参数:
      key - Redis键名
      value - 值
      score - 排序号
    • rangeByScore

      public Set<String> rangeByScore(String key, double startScore, double endScore)
      有序集合-获取指定范围
      参数:
      key - Redis键
      startScore - 开始序号
      endScore - 结束序号
      返回:
      集合
    • keys

      public Set<String> keys(String pattern)
      模糊查询Redis键名
      参数:
      pattern - 键名包含字符串(如:myKey*)
      返回:
      集合
    • hashMapList

      public List hashMapList(Collection<String> keySet)
      获取多个hashMap
      参数:
      keySet - key集合
      返回:
      列表
    • batchHashMapSet

      public void batchHashMapSet(com.google.common.collect.HashMultimap<String,Map<String,String>> batchMap)
      保存多个哈希表(HashMap)(Redis键名可重复)
      参数:
      batchMap - map对象
    • batchHashMapSet

      public void batchHashMapSet(Map<String,Map<String,String>> dataMap)
      保存多个哈希表(HashMap)(Redis键名不可以重复)
      参数:
      dataMap - map对象
    • batchHashMapListSet

      public void batchHashMapListSet(List<Map<String,Map<String,String>>> list)
      保存多个哈希表(HashMap)列表(哈希map的Redis键名不能重复)
      参数:
      list - 列表
    • getExpire

      public Long getExpire(String key)
      获取超时时间
      参数:
      key - Redis键名
      返回:
      过期时间
    • getExpire

      public Long getExpire(String key, TimeUnit timeUnit)
      获取超时时间
      参数:
      key - Redis键名
      timeUnit - 时间单位
      返回:
      过期时间