public class RedisRepository extends Object
| 构造器和说明 |
|---|
RedisRepository(org.springframework.data.redis.core.RedisTemplate<String,Object> redisTemplate,
org.springframework.data.redis.core.StringRedisTemplate stringRedisTemplate) |
| 限定符和类型 | 方法和说明 |
|---|---|
Long |
decr(String key)
将 key 中储存的数字值减一。
|
Long |
decrBy(String key,
long longValue)
将 key 所储存的值减去减量 decrement 。
|
Boolean |
del(CacheKey key)
删除给定的一个 key
不存在的 key 会被忽略。
|
Long |
del(Collection<String> keys)
删除给定的多个 key
不存在的 key 会被忽略。
|
Long |
del(String... keys)
删除给定的多个 key
不存在的 key 会被忽略。
|
Boolean |
del(String key)
删除给定的一个 key
不存在的 key 会被忽略。
|
Boolean |
exists(String key)
检查给定 key 是否存在。
|
Boolean |
expire(String key,
Duration timeout)
为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。
|
Boolean |
expire(String key,
long seconds)
为给定 key 设置生存时间,当 key 过期时(生存时间为 0 ),它会被自动删除。
|
Boolean |
expireAt(String key,
Date date)
EXPIREAT 的作用和 EXPIRE 类似,都用于为 key 设置生存时间。
|
Boolean |
expireAt(String key,
long unixTime)
EXPIREAT 的作用和 EXPIRE 类似,都用于为 key 设置生存时间。
|
<T> T |
get(CacheKey cacheKey)
返回 key 所关联的 value 值
如果 key 不存在那么返回特殊值 nil 。
|
<T> T |
get(CacheKey cacheKey,
Supplier<T> loader)
获取cache 为 null 时使用加载器,然后设置缓存
|
<T> T |
get(String key)
返回 key 所关联的 value 值
如果 key 不存在那么返回特殊值 nil 。
|
<T> T |
get(String key,
Supplier<T> loader)
获取cache 为 null 时使用加载器,然后设置缓存
|
Long |
getCounter(String key)
获取记数器的值
|
<T> T |
getSet(String key,
Object value)
将给定 key 的值设为 value ,并返回 key 的旧值(old value)。
|
Long |
hDel(String key,
Object... fields)
删除哈希表 key 中的一个或多个指定域,不存在的域将被忽略。
|
Boolean |
hExists(String key,
Object field)
查看哈希表 key 中,给定域 field 是否存在。
|
<T> T |
hGet(String key,
Object field)
返回哈希表 key 中给定域 field 的值。
|
Map |
hGetAll(String key)
返回哈希表 key 中,所有的域和值。
|
Long |
hIncrBy(String key,
Object field,
long value)
为哈希表 key 中的域 field 的值加上增量 increment 。
|
Double |
hIncrByFloat(String key,
Object field,
double value)
为哈希表 key 中的域 field 加上浮点数增量 increment 。
|
Set<Object> |
hKeys(String key)
返回哈希表 key 中的所有域。
|
Long |
hLen(String key)
返回哈希表 key 中域的数量。
|
List |
hmGet(String key,
Collection<Object> hashKeys)
返回哈希表 key 中,一个或多个给定域的值。
|
List |
hmGet(String key,
Object... fields)
返回哈希表 key 中,一个或多个给定域的值。
|
void |
hMset(String key,
Map<Object,Object> hash)
同时将多个 field-value (域-值)对设置到哈希表 key 中。
|
void |
hSet(String key,
Object field,
Object value)
将哈希表 key 中的域 field 的值设为 value 。
|
List |
hVals(String key)
返回哈希表 key 中所有域的值。
|
Long |
incr(String key)
将 key 中储存的数字值增一。
|
Long |
incrBy(String key,
long longValue)
将 key 所储存的值加上增量 increment 。
|
Set<String> |
keys(String pattern)
查找所有符合给定模式 pattern 的 key 。
|
<T> T |
lIndex(String key,
long index)
返回列表 key 中,下标为 index 的元素。
|
Long |
lLen(String key)
返回列表 key 的长度。
|
<T> T |
lPop(String key)
移除并返回列表 key 的头元素。
|
Long |
lPush(String key,
Object... values)
将一个或多个值 value 插入到列表 key 的表头
如果有多个 value 值,那么各个 value 值按从左到右的顺序依次插入到表头: 比如说,
对空列表 mylist 执行命令 LPUSH mylist a b c ,列表的值将是 c b a ,
这等同于原子性地执行 LPUSH mylist a 、 LPUSH mylist b 和 LPUSH mylist c 三个命令。
|
List |
lRange(String key,
long start,
long end)
返回列表 key 中指定区间内的元素,区间以偏移量 start 和 stop 指定。
|
Long |
lRem(String key,
long count,
Object value)
根据参数 count 的值,移除列表中与参数 value 相等的元素。
|
void |
lSet(String key,
long index,
Object value)
将列表 key 下标为 index 的元素的值设置为 value 。
|
void |
lTrim(String key,
long start,
long end)
对一个列表进行修剪(trim),就是说,让列表只保留指定区间内的元素,不在指定区间之内的元素都将被删除。
|
List<Object> |
mGet(Collection<String> keys)
返回所有(一个或多个)给定 key 的值。
|
List<Object> |
mGet(String... keys)
返回所有(一个或多个)给定 key 的值。
|
Boolean |
move(String key,
int dbIndex)
将当前数据库的 key 移动到给定的数据库 db 当中。
|
void |
mSet(Object... keysValues)
同时设置一个或多个 key-value 对。
|
Boolean |
persist(String key)
移除给定 key 的生存时间,将这个 key 从『易失的』(带生存时间 key )转换成『持久的』(一个不带生存时间、永不过期的 key )。
|
Boolean |
pexpire(String key,
long milliseconds)
这个命令和 EXPIRE 命令的作用类似,但是它以毫秒为单位设置 key 的生存时间,而不像 EXPIRE 命令那样,以秒为单位。
|
Long |
pttl(String key)
这个命令类似于 TTL 命令,但它以毫秒为单位返回 key 的剩余生存时间,而不是像 TTL 命令那样,以秒为单位。
|
String |
randomKey()
从当前数据库中随机返回(不删除)一个 key 。
|
void |
rename(String oldkey,
String newkey)
将 key 改名为 newkey 。
|
<T> T |
rPop(String key)
移除并返回列表 key 的尾元素。
|
<T> T |
rPopLPush(String srcKey,
String dstKey)
命令 RPOPLPUSH 在一个原子时间内,执行以下两个动作:
将列表 source 中的最后一个元素(尾元素)弹出,并返回给客户端。
|
Long |
rPush(String key,
Object... values)
将一个或多个值 value 插入到列表 key 的表尾(最右边)。
|
Long |
sAdd(String key,
Object... members)
将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。
|
Set |
sDiff(String key,
Collection<String> otherKeys)
返回一个集合的全部成员,该集合是所有给定集合之间的差集。
|
Set |
sDiff(String key,
String otherKey)
返回一个集合的全部成员,该集合是所有给定集合之间的差集。
|
void |
set(CacheKey cacheKey,
Object value)
设置缓存
|
void |
set(String key,
Object value)
存放 key value 对到 redis。
|
void |
setEx(String key,
Object value,
Duration timeout)
存放 key value 对到 redis,并将 key 的生存时间设为 seconds (以秒为单位)。
|
void |
setEx(String key,
Object value,
Long seconds)
存放 key value 对到 redis,并将 key 的生存时间设为 seconds (以秒为单位)。
|
Set |
sInter(String key,
Collection<String> otherKeys)
返回多个集合的交集,多个集合由 keys 指定
|
Set |
sInter(String key,
String otherKey)
返回多个集合的交集,多个集合由 keys 指定
|
boolean |
sIsMember(String key,
Object member)
判断 member 元素是否集合 key 的成员。
|
Set |
sMembers(String key)
返回集合 key 中的所有成员。
|
<T> T |
sPop(String key)
移除并返回集合中的一个随机元素。
|
<T> T |
sRandMember(String key)
返回集合中的一个随机元素。
|
List |
sRandMember(String key,
int count)
返回集合中的 count 个随机元素。
|
Long |
sRem(String key,
Object... members)
移除集合 key 中的一个或多个 member 元素,不存在的 member 元素会被忽略。
|
Set |
sUnion(String key,
Collection<String> otherKeys)
返回多个集合的并集,多个集合由 keys 指定
不存在的 key 被视为空集。
|
Set |
sUnion(String key,
String otherKey)
返回多个集合的并集,多个集合由 keys 指定
不存在的 key 被视为空集。
|
Long |
ttl(String key)
以秒为单位,返回给定 key 的剩余生存时间(TTL, time to live)。
|
String |
type(String key)
返回 key 所储存的值的类型。
|
Long |
zAdd(String key,
Map<Object,Double> scoreMembers)
将一个或多个 member 元素及其 score 值加入到有序集 key 当中。
|
Boolean |
zAdd(String key,
Object member,
double score)
将一个或多个 member 元素及其 score 值加入到有序集 key 当中。
|
Long |
zCard(String key)
返回有序集 key 的基数。
|
Long |
zCount(String key,
double min,
double max)
返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。
|
Double |
zIncrBy(String key,
Object member,
double score)
为有序集 key 的成员 member 的 score 值加上增量 increment 。
|
Set |
zRange(String key,
long start,
long end)
返回有序集 key 中,指定区间内的成员。
|
Set |
zRangeByScore(String key,
double min,
double max)
返回有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。
|
Long |
zRank(String key,
Object member)
返回有序集 key 中成员 member 的排名。
|
Long |
zRem(String key,
Object... members)
移除有序集 key 中的一个或多个成员,不存在的成员将被忽略。
|
Set |
zRevrange(String key,
long start,
long end)
返回有序集 key 中,指定区间内的成员。
|
Long |
zRevrank(String key,
Object member)
返回有序集 key 中成员 member 的排名。
|
Double |
zScore(String key,
Object member)
返回有序集 key 中,成员 member 的 score 值。
|
public void setEx(String key, Object value, Duration timeout)
public void setEx(String key, Object value, Long seconds)
@Nullable public <T> T get(String key)
@Nullable public <T> T get(String key, Supplier<T> loader)
T - 泛型key - cacheKeyloader - cache loader@Nullable public <T> T get(CacheKey cacheKey)
@Nullable public <T> T get(CacheKey cacheKey, Supplier<T> loader)
T - 泛型cacheKey - cacheKeyloader - cache loaderpublic Long del(Collection<String> keys)
public Set<String> keys(String pattern)
public void mSet(Object... keysValues)
例子:
Cache cache = RedisKit.use(); // 使用 Redis 的 cache
cache.mset("k1", "v1", "k2", "v2"); // 放入多个 key value 键值对
List list = cache.mget("k1", "k2"); // 利用多个键值得到上面代码放入的值
public List<Object> mGet(String... keys)
public List<Object> mGet(Collection<String> keys)
public Long decr(String key)
public Long decrBy(String key, long longValue)
public Long incr(String key)
public Long incrBy(String key, long longValue)
public String randomKey()
public void rename(String oldkey, String newkey)
public Boolean move(String key, int dbIndex)
public Boolean expire(String key, long seconds)
public Boolean expire(String key, Duration timeout)
public Boolean expireAt(String key, Date date)
public Boolean expireAt(String key, long unixTime)
public Boolean pexpire(String key, long milliseconds)
public <T> T getSet(String key, Object value)
public Boolean persist(String key)
public void hSet(String key, Object field, Object value)
public void hMset(String key, Map<Object,Object> hash)
public List hmGet(String key, Object... fields)
public List hmGet(String key, Collection<Object> hashKeys)
public Map hGetAll(String key)
public Long hIncrBy(String key, Object field, long value)
public Double hIncrByFloat(String key, Object field, double value)
public <T> T lIndex(String key, long index)
public Long lLen(String key)
public <T> T lPop(String key)
public Long lPush(String key, Object... values)
public void lSet(String key, long index, Object value)
public Long lRem(String key, long count, Object value)
public List lRange(String key, long start, long end)
例子: 获取 list 中所有数据:cache.lrange(listKey, 0, -1); 获取 list 中下标 1 到 3 的数据: cache.lrange(listKey, 1, 3);
public void lTrim(String key, long start, long end)
public <T> T rPop(String key)
public Long rPush(String key, Object... values)
public <T> T rPopLPush(String srcKey, String dstKey)
public Long sAdd(String key, Object... members)
public <T> T sPop(String key)
public Set sInter(String key, Collection<String> otherKeys)
public <T> T sRandMember(String key)
public List sRandMember(String key, int count)
public Set sUnion(String key, Collection<String> otherKeys)
public Set sDiff(String key, Collection<String> otherKeys)
public Boolean zAdd(String key, Object member, double score)
public Long zAdd(String key, Map<Object,Double> scoreMembers)
public Long zCount(String key, double min, double max)
public Double zIncrBy(String key, Object member, double score)
public Set zRange(String key, long start, long end)
public Set zRevrange(String key, long start, long end)
public Set zRangeByScore(String key, double min, double max)
public Long zRank(String key, Object member)
public Long zRevrank(String key, Object member)
public Long zRem(String key, Object... members)
Copyright © 2023. All rights reserved.