public class RedisUtil extends Object
| Constructor and Description |
|---|
RedisUtil() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(String key,
Object value,
double score)
添加 ZSet 元素
|
Long |
add(String key,
String... values)
添加 set 元素
|
Long |
batchAddZset(String key,
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> tuples)
批量添加 Zset
Set TypedTuple |
long |
countZSet(String key,
double min,
double max)
返回指定分数区间 [min,max] 的元素个数
|
boolean |
delete(String key)
删除 key-value
|
Long |
delete(String key,
String... hashKeys)
删除指定 hash 的 HashKey
|
Set<Object> |
difference(String key,
Collection<Object> collections)
获取 key 和 集合 collections 中的 key 集合的差集
|
Set<Object> |
difference(String key,
String otherkey)
获取两个集合的差集
|
Long |
differenceAndStore(String key,
Collection<Object> collections,
String newKey)
将 key 和 集合 collections 中的 key 集合的差集 添加到 newkey 集合中
|
Long |
differenceAndStore(String key,
String otherkey,
String newKey)
将 key 与 otherkey 的差集 ,添加到新的 newKey 集合中
|
boolean |
expire(String key,
long time)
给一个指定的 key 值附加过期时间
|
boolean |
expire(String key,
long time,
TimeUnit type)
给一个指定的 key 值附加过期时间
|
String |
get(String key)
获取 String 类型 key-value
|
String |
getAndSet(String key,
String value)
如果 key 存在则覆盖,并返回旧值.
|
Long |
getExpire(String key)
获取指定key 的过期时间
|
Map<Object,Object> |
getHashEntries(String key)
获取 key 下的 所有 hashkey 和 value
|
Object |
getHashKey(String key,
String hashKey)
获取指定 key 下的 hashkey
|
org.springframework.data.redis.core.RedisTemplate<Object,Object> |
getInstance() |
boolean |
hashKey(String key,
String hashKey)
验证指定 key 下 有没有指定的 hashkey
|
Set<Object> |
hashKeys(String key)
获取 key 下的 所有 hashkey 字段名
|
Long |
hashSize(String key)
获取指定 hash 下面的 键值对 数量
|
Double |
increment(String key,
double number)
对一个 key-value 的值进行加减操作,
如果该 key 不存在 将创建一个key 并赋值该 number
如果 key 存在,但 value 不是 纯数字 ,将报错
|
Long |
increment(String key,
long number)
对一个 key-value 的值进行加减操作,
如果该 key 不存在 将创建一个key 并赋值该 number
如果 key 存在,但 value 不是长整型 ,将报错
|
Double |
increment(String key,
String hashKey,
Double number)
给指定 hash 的 hashkey 做增减操作
|
Long |
increment(String key,
String hashKey,
long number)
给指定 hash 的 hashkey 做增减操作
|
Double |
incrementScore(String key,
Object value,
double score)
对指定的 zset 的 value 值 , socre 属性做增减操作
|
Long |
intersectAndStore(String key,
Collection<String> collections,
String destKey)
key 和 collections 多个集合的交集,保存在 destKey 集合中
|
Long |
intersectAndStore(String key,
String otherKey,
String destKey)
key 和 otherKey 两个集合的交集,保存在 destKey 集合中
|
boolean |
isMember(String key,
Object value)
判断 set 集合中 是否有 value
|
Set<String> |
keys(String pattern) |
Object |
leftPop(String key)
指定 list 从左出栈
如果列表没有元素,会堵塞到列表一直有元素或者超时为止
|
Long |
leftPush(String key,
Object value)
指定 list 从左入栈
|
Long |
leftPushAll(String key,
Collection<Object> values)
从左边依次入栈
导入顺序按照 Collection 顺序
如: a b c => c b a
|
List<Object> |
listRange(String key,
long start,
long end)
获取列表 指定范围内的所有值
|
Long |
listRemove(String key,
long count,
Object value)
删除 key 中 值为 value 的 count 个数.
|
Long |
listSize(String key,
long index)
获取列表指定长度
|
void |
listTrim(String key,
long start,
long end)
删除 列表 [start,end] 以外的所有元素
|
Set<Object> |
members(String key)
返回集合中所有元素
|
boolean |
moveSet(String key,
Object value,
String destKey)
将 key 中的 value 转入到 destKey 中
|
void |
multiSet(Map<String,String> keyAndValue)
批量添加 key-value (重复的键会覆盖)
|
void |
multiSetIfAbsent(Map<String,String> keyAndValue)
批量添加 key-value 只有在键不存在时,才添加
map 中只要有一个key存在,则全部不添加
|
Object |
popIndex(String key,
long index)
根据下标获取值
|
void |
put(String key,
String hashKey,
String value)
添加 Hash 键值对
|
void |
putAll(String key,
Map<String,String> map)
批量添加 hash 的 键值对
有则覆盖,没有则添加
|
boolean |
putIfAbsent(String key,
String hashKey,
String value)
添加 hash 键值对.
|
Object |
randomGet(String key)
随机获取一个元素
|
List<Object> |
randomGet(String key,
long count)
随机获取指定数量的元素,同一个元素可能会选中两次
|
Set<Object> |
randomGetDistinct(String key,
long count)
随机获取指定数量的元素,去重(同一个元素只能选择一次)
|
Object |
randomPop(String key)
随机移除一个集合中的元素,并返回出来
|
Set<Object> |
range(String key,
long start,
long end)
获取索引区间内的排序结果集合(从0开始,从小到大,只有列名)
|
Set<Object> |
rangeByScore(String key,
double min,
double max)
获取分数范围内的 [min,max] 的排序结果集合 (从小到大,只有列名)
|
Set<Object> |
rangeByScore(String key,
double min,
double max,
long offset,
long count)
返回 分数范围内 指定 count 数量的元素集合, 并且从 offset 下标开始(从小到大,不带分数的集合)
|
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> |
rangeByScoreWithScores(String key,
double min,
double max)
获取分数范围内的 [min,max] 的排序结果集合 (从小到大,集合带分数)
|
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> |
rangeByScoreWithScores(String key,
double min,
double max,
long offset,
long count)
返回 分数范围内 指定 count 数量的元素集合, 并且从 offset 下标开始(从小到大,带分数的集合)
|
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> |
rangeWithScores(String key,
long start,
long end)
获取索引区间内的排序结果集合(从0开始,从小到大,带上分数)
|
Long |
rank(String key,
Object value)
获取 key 中指定 value 的排名(从0开始,从小到大排序)
|
Long |
remove(String key,
Object... values)
删除集合中一个或多个的指定值
|
boolean |
removeExpire(String key)
移除指定key 的过期时间
|
Long |
removeRange(String key,
long start,
long end)
删除指定索引位置的成员,其中成员分数按( 从小到大 )
|
Long |
removeRangeByScore(String key,
double min,
double max)
删除指定 分数范围 内的成员 [main,max],其中成员分数按( 从小到大 )
|
Long |
removeZset(String key,
String... values)
Zset 删除一个或多个元素
|
void |
rename(String key,
String newKey)
修改 key
|
Set<Object> |
reverseRange(String key,
long start,
long end)
获取索引区间内的排序结果集合(从0开始,从大到小,只有列名)
|
Set<Object> |
reverseRangeByScore(String key,
double min,
double max)
获取分数范围内的 [min,max] 的排序结果集合 (从大到小,集合不带分数)
|
Set<Object> |
reverseRangeByScore(String key,
double min,
double max,
long offset,
long count)
返回 分数范围内 指定 count 数量的元素集合, 并且从 offset 下标开始(从大到小,不带分数的集合)
|
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> |
reverseRangeByScoreWithScores(String key,
double min,
double max)
获取分数范围内的 [min,max] 的排序结果集合 (从大到小,集合带分数)
|
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> |
reverseRangeByScoreWithScores(String key,
double min,
double max,
long offset,
long count)
返回 分数范围内 指定 count 数量的元素集合, 并且从 offset 下标开始(从大到小,带分数的集合)
|
Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> |
reverseRangeWithScores(String key,
long start,
long end)
获取索引区间内的排序结果集合(从0开始,从大到小,带上分数)
|
Long |
reverseRank(String key,
Object value)
获取 key 中指定 value 的排名(从0开始,从大到小排序)
|
Object |
rightPop(String key)
指定 list 从右出栈
如果列表没有元素,会堵塞到列表一直有元素或者超时为止
|
Object |
rightPopAndLeftPush(String key,
String key2)
将 key 右出栈,并左入栈到 key2
|
Long |
rightPush(String key,
Object value)
指定 list 从右入栈
|
Long |
rightPushAll(String key,
Collection<Object> values)
从右边依次入栈
导入顺序按照 Collection 顺序
如: a b c => a b c
|
Double |
score(String key,
Object value)
获取指定成员的 score 值
|
void |
set(String key,
String value)
设置 String 类型 key-value
|
void |
set(String key,
String value,
long time)
设置 String 类型 key-value 并添加过期时间 (秒单位)
|
void |
set(String key,
String value,
long time,
TimeUnit unit)
设置 String 类型 key-value 并添加过期时间 (分钟单位)
|
Long |
setSize(String key)
无序集合的大小
|
long |
sizeZset(String key)
返回 zset 集合数量
|
Long |
unionAndStoreSet(String key,
Collection<Object> collections,
String destKey)
将 key 与 collections 的并集,保存到 destKey 中
|
Long |
unionAndStoreSet(String key,
String otherKey,
String destKey)
将 key 与 otherKey 的并集,保存到 destKey 中
|
Long |
unionAndStoreZset(String key,
Collection<String> collections,
String destKey)
key 和 collections 集合的并集,保存在 destKey 集合中, 列名相同的 score 相加
|
Long |
unionAndStoreZset(String key,
String otherKey,
String destKey)
key 和 other 两个集合的并集,保存在 destKey 集合中, 列名相同的 score 相加
|
Set<Object> |
unionSet(String key,
Collection<Object> collections)
返回 key 和 collections 的并集
|
Set<Object> |
unionSet(String key,
String otherKey)
返回 key 和 othere 的并集
|
public void set(String key, String value, long time)
key - value - time - 过期时间,毫秒单位public void set(String key, String value, long time, TimeUnit unit)
key - value - time - 过期时间unit - 时间单位public String getAndSet(String key, String value)
key - value - public void multiSet(Map<String,String> keyAndValue)
keyAndValue - public void multiSetIfAbsent(Map<String,String> keyAndValue)
keyAndValue - public Long increment(String key, long number)
key - number - public Double increment(String key, double number)
key - number - public boolean expire(String key, long time)
key - time - 过期时间,秒public boolean expire(String key, long time, TimeUnit type)
key - time - type - public boolean removeExpire(String key)
key - public boolean delete(String key)
key - public void put(String key, String hashKey, String value)
key - hashKey - value - public void putAll(String key, Map<String,String> map)
key - map - public boolean putIfAbsent(String key, String hashKey, String value)
key - hashKey - value - public Long delete(String key, String... hashKeys)
key - hashKeys - public Long increment(String key, String hashKey, long number)
key - hashKey - number - public Double increment(String key, String hashKey, Double number)
key - hashKey - number - public Object getHashKey(String key, String hashKey)
key - hashKey - public Map<Object,Object> getHashEntries(String key)
key - public boolean hashKey(String key, String hashKey)
key - hashKey - public Set<Object> hashKeys(String key)
key - public Long leftPush(String key, Object value)
key - public Object leftPop(String key)
key - public Long leftPushAll(String key, Collection<Object> values)
key - values - public Long rightPush(String key, Object value)
key - public Object rightPop(String key)
key - public Long rightPushAll(String key, Collection<Object> values)
key - values - public List<Object> listRange(String key, long start, long end)
key - start - end - public Long listRemove(String key, long count, Object value)
key - count - value - public void listTrim(String key, long start, long end)
key - start - end - public Object rightPopAndLeftPush(String key, String key2)
key - 右出栈的列表key2 - 左入栈的列表public Set<Object> difference(String key, String otherkey)
key - otherkey - public Set<Object> difference(String key, Collection<Object> collections)
key - collections - public Long differenceAndStore(String key, String otherkey, String newKey)
key - otherkey - newKey - public Long differenceAndStore(String key, Collection<Object> collections, String newKey)
key - collections - newKey - public Long remove(String key, Object... values)
key - values - public List<Object> randomGet(String key, long count)
key - count - public Set<Object> randomGetDistinct(String key, long count)
key - count - public boolean moveSet(String key, Object value, String destKey)
key - value - destKey - public boolean isMember(String key, Object value)
key - value - public Set<Object> unionSet(String key, String otherKey)
key - otherKey - public Set<Object> unionSet(String key, Collection<Object> collections)
key - collections - key 的集合public Long unionAndStoreSet(String key, String otherKey, String destKey)
key - otherKey - destKey - public Long unionAndStoreSet(String key, Collection<Object> collections, String destKey)
key - collections - destKey - public boolean add(String key, Object value, double score)
key - value - score - public Long batchAddZset(String key, Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> tuples)
key - tuples - public Long removeZset(String key, String... values)
key - values - public Double incrementScore(String key, Object value, double score)
key - value - score - public Long rank(String key, Object value)
key - value - public Long reverseRank(String key, Object value)
key - value - public Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> rangeWithScores(String key, long start, long end)
key - start - end - public Set<Object> range(String key, long start, long end)
key - start - end - public Set<Object> rangeByScore(String key, double min, double max)
key - min - max - public Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> rangeByScoreWithScores(String key, double min, double max)
key - min - max - public Set<Object> rangeByScore(String key, double min, double max, long offset, long count)
key - min - max - offset - 从指定下标开始count - 输出指定元素数量public Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> rangeByScoreWithScores(String key, double min, double max, long offset, long count)
key - min - max - offset - 从指定下标开始count - 输出指定元素数量public Set<Object> reverseRange(String key, long start, long end)
key - start - end - public Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> reverseRangeWithScores(String key, long start, long end)
key - start - end - public Set<Object> reverseRangeByScore(String key, double min, double max)
key - min - max - public Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> reverseRangeByScoreWithScores(String key, double min, double max)
key - min - max - public Set<Object> reverseRangeByScore(String key, double min, double max, long offset, long count)
key - min - max - offset - 从指定下标开始count - 输出指定元素数量public Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<Object>> reverseRangeByScoreWithScores(String key, double min, double max, long offset, long count)
key - min - max - offset - 从指定下标开始count - 输出指定元素数量public long countZSet(String key, double min, double max)
key - min - max - public long sizeZset(String key)
key - public Double score(String key, Object value)
key - value - public Long removeRange(String key, long start, long end)
key - start - end - public Long removeRangeByScore(String key, double min, double max)
key - min - max - public Long unionAndStoreZset(String key, String otherKey, String destKey)
key - otherKey - destKey - public Long unionAndStoreZset(String key, Collection<String> collections, String destKey)
key - collections - destKey - public Long intersectAndStore(String key, String otherKey, String destKey)
key - otherKey - destKey - public Long intersectAndStore(String key, Collection<String> collections, String destKey)
key - collections - destKey - Copyright © 2019. All rights reserved.