Package cn.sinozg.applet.common.utils
Class RedisUtil
java.lang.Object
cn.sinozg.applet.common.utils.RedisUtil
redis 工具类
-
Field Summary
FieldsModifier and TypeFieldDescription -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T>cacheByPipelined(List<String> keyList) 管道模式获取到数据static booleandeleteKeys(String key) 根据key 批量删除static booleandeleteObject(String key) 删除单个对象static longdeleteObject(Collection<String> collection) 删除集合对象static boolean设置有效时间static boolean设置有效时间static boolean设置有效期getCacheMap(String key) 获得缓存的Mapstatic <T> TgetCacheObject(String key) 获得缓存的基本对象。static long获取自增长的数值static long获取自增长的数值static Collection<String>获得缓存的基本对象列表static void添加mapstatic void删除map里的某些static LongobjExpireTime(String key) 判断是否有效rangeWithScore(String key, long start, long end) 查询集合中指定顺序的值和score,0, -1 表示获取全部的集合内容static LongremoveCacheSet(String key, Object... value) 删除元素 zremstatic LongremoveRangeCacheSet(String key, long start, long end) 删除元素 zremstatic <T> voidsetCacheMap(String key, Map<String, T> dataMap) 缓存Mapstatic <T> voidsetCacheObject(String key, T value) 缓存基本的对象,Integer、String、实体类等static <T> voidsetCacheObject(String key, T value, long timeout) 设置缓存static <T> voidsetCacheObject(String key, T value, long timeout, TimeUnit timeUnit) 缓存基本的对象,Integer、String、实体类等static <T> voidsetCacheObject(String key, T value, Duration duration) static <T> void通过管道模式写入数据static BooleansetCacheSet(String key, String value, double score) 添加一个元素, zset与set最大的区别就是每个元素都有一个score,因此有个排序的辅助功能;static <T> booleansetIfAbsentObject(String key, T value, Duration duration) 设置值 如果不存在就设置static long设置自增长的值sortRangeWithScoresCacheSet(String key, double min, double max) 根据score的值,来获取满足条件的集合
-
Field Details
-
REDIS_TEMPLATE
-
STRING_REDIS_TEMPLATE
-
-
Constructor Details
-
RedisUtil
public RedisUtil()
-
-
Method Details
-
setCacheObject
缓存基本的对象,Integer、String、实体类等- Parameters:
key- 缓存的键值value- 缓存的值
-
setCacheObject
缓存基本的对象,Integer、String、实体类等- Parameters:
key- 缓存的键值value- 缓存的值timeout- 时间timeUnit- 时间颗粒度
-
setCacheObject
设置缓存- Type Parameters:
T- value的类型- Parameters:
key- keyvalue- 值timeout- 有效时间
-
setCacheObject
- Type Parameters:
T- value的类型- Parameters:
key- keyvalue- 值duration- 有效时间
-
setCacheObjectBatch
public static <T> void setCacheObjectBatch(Map<String, T> data, Function<String, String> fun, Duration duration) 通过管道模式写入数据- Type Parameters:
T- 数据类型- Parameters:
data- 数据fun- 处理key值duration- 过期时间
-
setIfAbsentObject
设置值 如果不存在就设置并且key存在返回false,key不存在就返回ture
- Type Parameters:
T- 类型- Parameters:
key- keyvalue- valueduration- 有效期- Returns:
- key是否存在
-
expire
设置有效时间- Parameters:
key- Redis键timeout- 超时时间- Returns:
- true=设置成功;false=设置失败
-
expire
设置有效期- Parameters:
key- Redis键duration- 时间- Returns:
- true=设置成功;false=设置失败
-
expire
设置有效时间- Parameters:
key- Redis键timeout- 超时时间unit- 时间单位- Returns:
- true=设置成功;false=设置失败
-
objExpireTime
判断是否有效- Parameters:
key- redis的key- Returns:
- 有效期
-
getCacheObject
获得缓存的基本对象。- Parameters:
key- 缓存键值- Returns:
- 缓存键值对应的数据
-
cacheByPipelined
管道模式获取到数据- Type Parameters:
T- 返回类型- Parameters:
keyList- key集合- Returns:
- 所有的value
-
deleteObject
删除单个对象- Parameters:
key- redis的key
-
deleteKeys
根据key 批量删除- Parameters:
key- key- Returns:
- 是否成功
-
deleteObject
删除集合对象- Parameters:
collection- 多个对象- Returns:
- 删除是否成功
-
getIncr
获取自增长的数值- Parameters:
key- key值duration- 过期时间 秒为单位- Returns:
- 返回当前的值
-
getIncr
获取自增长的数值- Parameters:
key- key值duration- 过期时间 秒为单位supplier- 初始化值- Returns:
- 返回当前的值
-
setIncr
设置自增长的值- Parameters:
key- redis keyvalue- 值- Returns:
- 返回当前值
-
setCacheMap
缓存Map- Parameters:
key- key值dataMap- 数据map
-
getCacheMap
获得缓存的Map- Parameters:
key- key值- Returns:
- 对应的map
-
mapPut
添加map- Parameters:
key- keyhashKey- map keyvalue- 值
-
mapRemove
删除map里的某些- Parameters:
key- keyhashKey- map key
-
keys
获得缓存的基本对象列表- Parameters:
pattern- 字符串前缀- Returns:
- 对象列表
-
setCacheSet
添加一个元素, zset与set最大的区别就是每个元素都有一个score,因此有个排序的辅助功能;- Parameters:
key- key值value- value值score- 权重
-
removeRangeCacheSet
删除元素 zrem- Parameters:
key- key值start- 开始end- 结束
-
removeCacheSet
删除元素 zrem- Parameters:
key- key值value- value值
-
rangeWithScore
public static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> rangeWithScore(String key, long start, long end) 查询集合中指定顺序的值和score,0, -1 表示获取全部的集合内容- Parameters:
key- key值start- 开始end- 结束- Returns:
- 结果集
-
sortRangeWithScoresCacheSet
public static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> sortRangeWithScoresCacheSet(String key, double min, double max) 根据score的值,来获取满足条件的集合- Parameters:
key- key值min- 最小值max- 最大值- Returns:
- 结果集
-