public class RedisUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static org.springframework.data.redis.core.RedisTemplate<String,Object> |
REDIS_TEMPLATE |
protected static org.springframework.data.redis.core.RedisTemplate<String,String> |
STRING_REDIS_TEMPLATE |
| Constructor and Description |
|---|
RedisUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <T> List<T> |
cacheByPipelined(List<String> keyList)
管道模式获取到数据
|
static boolean |
deleteKeys(String key)
根据key 批量删除
|
static long |
deleteObject(Collection<String> collection)
删除集合对象
|
static boolean |
deleteObject(String key)
删除单个对象
|
static boolean |
expire(String key,
Duration duration)
设置有效期
|
static boolean |
expire(String key,
long timeout)
设置有效时间
|
static boolean |
expire(String key,
long timeout,
TimeUnit unit)
设置有效时间
|
static <T> Map<String,T> |
getCacheMap(String key)
获得缓存的Map
|
static <T> T |
getCacheObject(String key)
获得缓存的基本对象。
|
static long |
getIncr(String key,
Duration duration)
获取自增长的数值
|
static long |
getIncr(String key,
Duration duration,
Supplier<Long> supplier)
获取自增长的数值
|
static Collection<String> |
keys(String pattern)
获得缓存的基本对象列表
|
static void |
mapPut(String key,
String hashKey,
String value)
添加map
|
static void |
mapRemove(String key,
Object... hashKey)
删除map里的某些
|
static Long |
objExpireTime(String key)
判断是否有效
|
static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> |
rangeWithScore(String key,
long start,
long end)
查询集合中指定顺序的值和score,0, -1 表示获取全部的集合内容
|
static Long |
removeCacheSet(String key,
Object... value)
删除元素 zrem
|
static Long |
removeRangeCacheSet(String key,
long start,
long end)
删除元素 zrem
|
static <T> void |
setCacheMap(String key,
Map<String,T> dataMap)
缓存Map
|
static <T> void |
setCacheObject(String key,
T value)
缓存基本的对象,Integer、String、实体类等
|
static <T> void |
setCacheObject(String key,
T value,
Duration duration) |
static <T> void |
setCacheObject(String key,
T value,
long timeout)
设置缓存
|
static <T> void |
setCacheObject(String key,
T value,
long timeout,
TimeUnit timeUnit)
缓存基本的对象,Integer、String、实体类等
|
static <T> void |
setCacheObjectBatch(Map<String,T> data,
Function<String,String> fun,
Duration duration)
通过管道模式写入数据
|
static Boolean |
setCacheSet(String key,
String value,
double score)
添加一个元素, zset与set最大的区别就是每个元素都有一个score,因此有个排序的辅助功能;
|
static <T> boolean |
setIfAbsentObject(String key,
T value,
Duration duration)
设置值 如果不存在就设置
并且key存在返回false,key不存在就返回ture
|
static long |
setIncr(String key,
long value)
设置自增长的值
|
static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> |
sortRangeWithScoresCacheSet(String key,
double min,
double max)
根据score的值,来获取满足条件的集合
|
protected static final org.springframework.data.redis.core.RedisTemplate<String,Object> REDIS_TEMPLATE
public static <T> void setCacheObject(String key, T value)
key - 缓存的键值value - 缓存的值public static <T> void setCacheObject(String key, T value, long timeout, TimeUnit timeUnit)
key - 缓存的键值value - 缓存的值timeout - 时间timeUnit - 时间颗粒度public static <T> void setCacheObject(String key, T value, long timeout)
T - value的类型key - keyvalue - 值timeout - 有效时间public static <T> void setCacheObject(String key, T value, Duration duration)
T - value的类型key - keyvalue - 值duration - 有效时间public static <T> void setCacheObjectBatch(Map<String,T> data, Function<String,String> fun, Duration duration)
T - 数据类型data - 数据fun - 处理key值duration - 过期时间public static <T> boolean setIfAbsentObject(String key, T value, Duration duration)
并且key存在返回false,key不存在就返回ture
T - 类型key - keyvalue - valueduration - 有效期public static boolean expire(String key, long timeout)
key - Redis键timeout - 超时时间public static boolean expire(String key, Duration duration)
key - Redis键duration - 时间public static boolean expire(String key, long timeout, TimeUnit unit)
key - Redis键timeout - 超时时间unit - 时间单位public static Long objExpireTime(String key)
key - redis的keypublic static <T> T getCacheObject(String key)
key - 缓存键值public static <T> List<T> cacheByPipelined(List<String> keyList)
T - 返回类型keyList - key集合public static boolean deleteObject(String key)
key - redis的keypublic static boolean deleteKeys(String key)
key - keypublic static long deleteObject(Collection<String> collection)
collection - 多个对象public static long getIncr(String key, Duration duration)
key - key值duration - 过期时间 秒为单位public static long getIncr(String key, Duration duration, Supplier<Long> supplier)
key - key值duration - 过期时间 秒为单位supplier - 初始化值public static long setIncr(String key, long value)
key - redis keyvalue - 值public static <T> void setCacheMap(String key, Map<String,T> dataMap)
key - key值dataMap - 数据mappublic static <T> Map<String,T> getCacheMap(String key)
key - key值public static void mapPut(String key, String hashKey, String value)
key - keyhashKey - map keyvalue - 值public static void mapRemove(String key, Object... hashKey)
key - keyhashKey - map keypublic static Collection<String> keys(String pattern)
pattern - 字符串前缀public static Boolean setCacheSet(String key, String value, double score)
key - key值value - value值score - 权重public static Long removeRangeCacheSet(String key, long start, long end)
key - key值start - 开始end - 结束public static Long removeCacheSet(String key, Object... value)
key - key值value - value值public static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> rangeWithScore(String key, long start, long end)
key - key值start - 开始end - 结束Copyright © 2024. All rights reserved.