Class RedisTemplateClient

java.lang.Object
com.codeupsoft.component.redis.client.RedisTemplateClient

public class RedisTemplateClient extends Object
Redis 模板客户端.
Author:
Liu,Dongdong
  • Constructor Details

    • RedisTemplateClient

      public RedisTemplateClient()
  • Method Details

    • expire

      public boolean expire(String key, long timeout, TimeUnit timeUnit)
      设置有效期.
      Parameters:
      key - 缓存键
      timeout - 过期时间
      timeUnit - 时间单位
      Returns:
      true=设置成功 false=设置失败
    • getExpire

      public long getExpire(String key, TimeUnit timeUnit)
      获取有效期.
      Parameters:
      key - 缓存键
      timeUnit - 时间单位
      Returns:
      有效期
    • hasKey

      public boolean hasKey(String key)
      判断key是否存在.
      Parameters:
      key - 缓存键
      Returns:
      true=存在 false=不存在
    • setCacheObject

      public <T> void setCacheObject(String key, T value)
      缓存基本对象(无过期时间).
      Type Parameters:
      T - 值类型
      Parameters:
      key - 缓存键
      value - 缓存值
    • setCacheObject

      public <T> void setCacheObject(String key, T value, long timeout, TimeUnit timeUnit)
      缓存基本对象(指定过期时间).
      Type Parameters:
      T - 值类型
      Parameters:
      key - 缓存键
      value - 缓存值
      timeout - 过期时间
      timeUnit - 时间单位
    • getCacheObject

      public <T> T getCacheObject(String key)
      获得缓存的基本对象.
      Type Parameters:
      T - 返回类型
      Parameters:
      key - 缓存键
      Returns:
      缓存值
    • getCacheObjectOrLoad

      public <T> T getCacheObjectOrLoad(String key, RedisCacheLoader<T> redisCacheLoader)
      获得缓存的基本对象.
      Type Parameters:
      T - 返回类型
      Parameters:
      key - 缓存键
      redisCacheLoader - 缓存加载器
      Returns:
      缓存值
    • getCacheObjectOrLoadWithLock

      public <T> T getCacheObjectOrLoadWithLock(String key, RedisLoadWithLock<T> redisLoadWithLock)
      获得缓存的基本对象.
      Type Parameters:
      T - 返回类型
      Parameters:
      key - 缓存键
      redisLoadWithLock - 缓存加载器
      Returns:
      缓存值
    • deleteObject

      public boolean deleteObject(String key)
      删除单个对象.
      Parameters:
      key - 缓存键
      Returns:
      true=删除成功 false=删除失败
    • deleteObject

      public long deleteObject(Collection<String> keys)
      删除集合对象.
      Parameters:
      keys - 缓存键集合
      Returns:
      删除数量
    • setCacheList

      public <T> long setCacheList(String key, List<T> dataList)
      缓存List数据.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      dataList - List数据
      Returns:
      缓存数据数量
    • setCacheList

      public <T> void setCacheList(String key, List<T> dataList, long timeout, TimeUnit timeUnit)
      缓存List数据(指定过期时间).
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      dataList - List数据
      timeout - 过期时间
      timeUnit - 时间单位
    • getCacheList

      public <T> List<T> getCacheList(String key)
      获得缓存的List对象.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      Returns:
      缓存的List对象
    • getCacheListOrLoad

      public <T> List<T> getCacheListOrLoad(String key, RedisCacheLoader<List<T>> redisCacheLoader)
      获得缓存的List对象(带缓存加载).
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      redisCacheLoader - 缓存加载器
      Returns:
      缓存的List对象
    • getCacheListOrLoadWithLock

      public <T> List<T> getCacheListOrLoadWithLock(String key, RedisLoadWithLock<List<T>> redisLoadWithLock)
      获得缓存的List对象(带锁的缓存加载).
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      redisLoadWithLock - 缓存加载器
      Returns:
      缓存的List对象
    • leftPushList

      public <T> long leftPushList(String key, T value)
      向List左侧添加元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      value - 元素值
      Returns:
      添加后List的长度
    • rightPushList

      public <T> long rightPushList(String key, T value)
      向List右侧添加元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      value - 元素值
      Returns:
      添加后List的长度
    • leftPopList

      public <T> T leftPopList(String key)
      从List左侧弹出元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      Returns:
      弹出的元素
    • rightPopList

      public <T> T rightPopList(String key)
      从List右侧弹出元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      Returns:
      弹出的元素
    • getListSize

      public long getListSize(String key)
      获取List的长度.
      Parameters:
      key - 缓存键
      Returns:
      List长度
    • getListIndex

      public <T> T getListIndex(String key, long index)
      根据索引获取List中的元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      index - 索引
      Returns:
      元素值
    • setCacheSet

      @SafeVarargs public final <T> long setCacheSet(String key, T... values)
      缓存Set数据.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      values - Set值
      Returns:
      添加的数量
    • setCacheSet

      @SafeVarargs public final <T> long setCacheSet(String key, long timeout, TimeUnit timeUnit, T... values)
      缓存Set数据(指定过期时间).
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      timeout - 过期时间
      timeUnit - 时间单位
      values - Set值
      Returns:
      添加的数量
    • getCacheSet

      public <T> Collection<T> getCacheSet(String key)
      获得缓存的Set对象.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      Returns:
      Set对象
    • isMemberOfSet

      public <T> boolean isMemberOfSet(String key, T value)
      判断Set中是否存在某个元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      value - 元素值
      Returns:
      true=存在 false=不存在
    • getSetSize

      public long getSetSize(String key)
      获取Set的大小.
      Parameters:
      key - 缓存键
      Returns:
      Set大小
    • removeSet

      @SafeVarargs public final <T> long removeSet(String key, T... values)
      移除Set中的元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      values - 元素值
      Returns:
      移除的个数
    • randomMemberOfSet

      public <T> T randomMemberOfSet(String key)
      随机获取Set中的元素.
      Type Parameters:
      T - 元素类型
      Parameters:
      key - 缓存键
      Returns:
      随机元素
    • setCacheMap

      public <K,V> void setCacheMap(String key, Map<K,V> dataMap)
      缓存Hash数据.
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      dataMap - Hash数据
    • setCacheMap

      public <K,V> void setCacheMap(String key, Map<K,V> dataMap, long timeout, TimeUnit timeUnit)
      缓存Hash数据(指定过期时间).
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      dataMap - Hash数据
      timeout - 过期时间
      timeUnit - 时间单位
    • putCacheMapValue

      public <K,V> void putCacheMapValue(String key, K hashKey, V value)
      向Hash中添加单个键值对.
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      hashKey - Hash键
      value - Hash值
    • getCacheMap

      public <K,V> Map<K,V> getCacheMap(String key)
      获得缓存的Hash对象.
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      Returns:
      Hash对象
    • getCacheMapOrLoad

      public <K,V> Map<K,V> getCacheMapOrLoad(String key, RedisCacheLoader<Map<K,V>> cacheLoader)
      获得缓存的Hash对象(带缓存加载).
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      cacheLoader - 缓存加载器
      Returns:
      Hash对象
    • getCacheMapOrLoadWithLock

      public <K,V> Map<K,V> getCacheMapOrLoadWithLock(String key, RedisLoadWithLock<Map<K,V>> redisLoadWithLock)
      获得缓存的Hash对象(带锁的缓存加载).
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      redisLoadWithLock - 缓存加载器
      Returns:
      Hash对象
    • getCacheMapValue

      public <K,V> V getCacheMapValue(String key, K hashKey)
      获取Hash中的单个值.
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      hashKey - Hash键
      Returns:
      Hash值
    • getMultiCacheMapValue

      public <K,V> List<V> getMultiCacheMapValue(String key, Collection<K> hashKeys)
      获取Hash中多个键的值.
      Type Parameters:
      K - Hash键类型
      V - Hash值类型
      Parameters:
      key - 缓存键
      hashKeys - Hash键集合
      Returns:
      Hash值列表
    • hasMapKey

      public <K> boolean hasMapKey(String key, K hashKey)
      判断Hash中是否存在某个键.
      Type Parameters:
      K - Hash键类型
      Parameters:
      key - 缓存键
      hashKey - Hash键
      Returns:
      true=存在 false=不存在
    • getMapSize

      public long getMapSize(String key)
      获取Hash的大小.
      Parameters:
      key - 缓存键
      Returns:
      Hash大小
    • deleteCacheMapValue

      @SafeVarargs public final <K> long deleteCacheMapValue(String key, K... hashKeys)
      删除Hash中的键.
      Type Parameters:
      K - Hash键类型
      Parameters:
      key - 缓存键
      hashKeys - Hash键
      Returns:
      删除的数量
    • increment

      public long increment(String key)
      自增(Long类型).
      Parameters:
      key - 缓存键
      Returns:
      自增后的值
    • increment

      public long increment(String key, long delta)
      自增指定值(Long类型).
      Parameters:
      key - 缓存键
      delta - 增量
      Returns:
      自增后的值
    • increment

      public double increment(String key, double delta)
      自增(Double类型).
      Parameters:
      key - 缓存键
      delta - 增量
      Returns:
      自增后的值
    • decrement

      public long decrement(String key)
      自减(Long类型).
      Parameters:
      key - 缓存键
      Returns:
      自减后的值
    • decrement

      public long decrement(String key, long delta)
      自减指定值(Long类型).
      Parameters:
      key - 缓存键
      delta - 减量
      Returns:
      自减后的值
    • incrementMapValue

      public <K> long incrementMapValue(String key, K hashKey, long delta)
      Hash字段自增.
      Type Parameters:
      K - Hash键类型
      Parameters:
      key - 缓存键
      hashKey - Hash键
      delta - 增量
      Returns:
      自增后的值
    • incrementMapValue

      public <K> double incrementMapValue(String key, K hashKey, double delta)
      Hash字段自增(Double类型).
      Type Parameters:
      K - Hash键类型
      Parameters:
      key - 缓存键
      hashKey - Hash键
      delta - 增量
      Returns:
      自增后的值