public class RedisRepositoryImpl extends Object implements CacheRepository
DEF_TIMEOUT_2H, DEF_TIMEOUT_5M| 构造器和说明 |
|---|
RedisRepositoryImpl(org.springframework.data.redis.core.RedisTemplate<String,Object> redisTemplate) |
| 限定符和类型 | 方法和说明 |
|---|---|
long |
dbSize()
集合数量
|
long |
del(String... keys)
删除key
|
void |
delHashValues(String key,
Object... hashKeys)
根据key值删除
|
boolean |
exists(String key)
判断某个主键是否存在
|
void |
flushDb()
清空redis存储的数据
|
void |
flushDb(org.springframework.data.redis.connection.RedisClusterNode node)
清空DB
|
byte[] |
get(byte[] key)
根据key获取对象
|
<T> T |
get(String key)
根据key获取对象
|
org.springframework.data.redis.connection.RedisConnectionFactory |
getConnectionFactory()
获取链接工厂
|
Map<String,Object> |
getHashValue(String key)
key只匹配map
|
<T> T |
getHashValues(String key,
String hashKey)
获取单个field对应的值
|
Map<String,Object> |
getKeysValues(String keyPatten)
根据key获取对象
|
<T> List<T> |
getList(String key,
int start,
int end)
redis List数据结构 : 返回列表 key 中指定区间内的元素,区间以偏移量 [start 和 end] 指定。
|
<T> T |
getOrDef(String key,
Function<String,? extends T> function)
根据key获取对象
不存在时,调用function回调获取数据,并set进入,然后返回
|
protected org.springframework.data.redis.serializer.RedisSerializer<String> |
getRedisSerializer()
获取 RedisSerializer
|
org.springframework.data.redis.core.RedisTemplate<String,Object> |
getRedisTemplate()
获取 RedisTemplate对象
|
long |
incr(String key)
对某个主键对应的值加一,value值必须是全数字的字符串
|
void |
insert(String key,
long index,
Object value)
redis List数据结构 : 将值 value 插入到列表 key 当中,位于值 index 之前或之后,默认之后。
|
Set<String> |
keys(String keyPatten)
查询在以keyPatten的所有 key
注意:
在服务器上执行 keys 命令是非常耗时的, 在使用该方法前,请三思!!!
|
Object |
leftPop(String key)
redis List数据结构 : 移除并返回列表 key 的头元素
|
Long |
leftPush(String key,
Object value)
redis List数据结构 : 将一个或多个值 value 插入到列表 key 的表头
|
<V> Long |
leftPushAll(String key,
List<V> list)
redis List数据结构 : 批量存储
|
Long |
length(String key)
redis List数据结构 : 返回列表 key 的长度 ; 如果 key 不存在,则 key 被解释为一个空列表,返回 0 ; 如果 key 不是列表类型,返回一个错误。
|
<T> org.springframework.data.redis.core.HashOperations<String,String,T> |
opsForHash()
Ops for hash hash operations.
|
org.springframework.data.redis.core.ListOperations<String,Object> |
opsForList()
redis List 引擎
|
void |
putHashValue(String key,
String hashKey,
Object hashValue)
对HashMap操作
|
void |
putHashValues(String key,
Map<String,Object> map)
批量添加
|
void |
remove(String key,
long i,
Object value)
redis List数据结构 : 根据参数 i 的值,移除列表中与参数 value 相等的元素
|
Object |
rightPop(String key)
redis List数据结构 : 移除并返回列表 key 的末尾元素
|
Long |
rightPush(String key,
Object value)
redis List数据结构 :将一个或多个值 value 插入到列表 key 的表尾(最右边)。
|
void |
set(String[] keys,
Object[] values)
一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销
|
void |
set(String key,
long index,
Object value)
redis List数据结构 : 将列表 key 下标为 index 的元素的值设置为 value
|
void |
set(String key,
Object value)
添加到缓存
|
void |
setExpire(byte[] key,
byte[] value,
long time)
添加到带有 过期时间的 缓存
|
void |
setExpire(String[] keys,
Object[] values,
long time)
一次性添加数组到 过期时间的 缓存,不用多次连接,节省开销
|
void |
setExpire(String key,
Object value,
long time)
添加到带有 过期时间的 缓存
|
List<String> |
willExpire(String key,
long time)
查询在这个时间段内即将过期的key
注意:
在服务器上执行 keys 命令是非常耗时的, 在使用该方法前,请三思!!!
|
public org.springframework.data.redis.connection.RedisConnectionFactory getConnectionFactory()
public org.springframework.data.redis.core.RedisTemplate<String,Object> getRedisTemplate()
public void flushDb(org.springframework.data.redis.connection.RedisClusterNode node)
node - redis 节点public void setExpire(byte[] key,
byte[] value,
long time)
key - redis主键value - 值time - 过期时间(单位秒)public void setExpire(String key, Object value, long time)
setExpire 在接口中 CacheRepositorykey - redis主键value - 值time - 过期时间(单位秒)public void setExpire(String[] keys, Object[] values, long time)
keys - redis主键数组values - 值数组time - 过期时间(单位秒)public void set(String[] keys, Object[] values)
keys - the keysvalues - the valuespublic void set(String key, Object value)
set 在接口中 CacheRepositorykey - the keyvalue - the valuepublic List<String> willExpire(String key, long time)
key - the keytime - the timepublic Set<String> keys(String keyPatten)
keyPatten - the key pattenpublic byte[] get(byte[] key)
key - the keypublic <T> T get(String key)
get 在接口中 CacheRepositorykey - the keypublic <T> T getOrDef(String key, Function<String,? extends T> function)
CacheRepositorygetOrDef 在接口中 CacheRepositorykey - redis主键public Map<String,Object> getKeysValues(String keyPatten)
keyPatten - the key pattenpublic <T> org.springframework.data.redis.core.HashOperations<String,String,T> opsForHash()
public void putHashValue(String key, String hashKey, Object hashValue)
key - the keyhashKey - the hash keyhashValue - the hash valuepublic <T> T getHashValues(String key, String hashKey)
key - the keyhashKey - the hash keypublic void delHashValues(String key, Object... hashKeys)
key - the keyhashKeys - the hash keyspublic Map<String,Object> getHashValue(String key)
key - the keypublic void putHashValues(String key, Map<String,Object> map)
key - the keymap - the mappublic long dbSize()
public void flushDb()
flushDb 在接口中 CacheRepositorypublic boolean exists(String key)
exists 在接口中 CacheRepositorykey - the keypublic long del(String... keys)
del 在接口中 CacheRepositorykeys - the keysprotected org.springframework.data.redis.serializer.RedisSerializer<String> getRedisSerializer()
public long incr(String key)
key - the keypublic org.springframework.data.redis.core.ListOperations<String,Object> opsForList()
public Long leftPush(String key, Object value)
key - the keyvalue - the valuepublic Object leftPop(String key)
key - the keypublic Long rightPush(String key, Object value)
key - the keyvalue - the valuepublic Object rightPop(String key)
key - the keypublic Long length(String key)
key - the keypublic void remove(String key, long i, Object value)
key - the keyi - thevalue - the valuepublic void set(String key, long index, Object value)
key - the keyindex - the indexvalue - the valuepublic <T> List<T> getList(String key, int start, int end)
key - the keystart - list的开始位置 (包含)end - list的结束位置 (包含)public <V> Long leftPushAll(String key, List<V> list)
key - the keylist - the listCopyright © 2020. All rights reserved.