public class RedisHelper extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static RedisHelper |
INSTANCE |
| 限定符和类型 | 方法和说明 |
|---|---|
static long |
decr(String key)
当 key 存在时,对其值进行自减操作 (自减步长为 1),当 key 不存在时,则先赋值为 0 再进行自减
|
static long |
decrBy(String key,
long delta)
当 key 存在时,对其值进行自减操作,当 key 不存在时,则先赋值为 0 再进行自减
|
static long |
del(Collection<String> keys) |
static long |
del(String... keys)
删除指定的 keys
|
static boolean |
del(String key)
删除指定的 key
|
static long |
delete(Collection<String> keys)
已过时。
use
del(Collection) |
static boolean |
delete(String key)
已过时。
use
del(String) |
static Object |
evalLua(String lua,
List<String> key,
Object... argv)
已过时。
RedisScript 应该做为单例,而不是每次生成,不推荐直接使用此方法
|
static <T> T |
execute(org.springframework.data.redis.core.RedisCallback<T> action)
执行 lua脚本
|
static <T> T |
execute(org.springframework.data.redis.core.RedisCallback<T> action,
boolean exposeConnection) |
static <T> T |
execute(org.springframework.data.redis.core.RedisCallback<T> action,
boolean exposeConnection,
boolean pipeline) |
static <T> T |
execute(org.springframework.data.redis.core.script.RedisScript<T> script,
List<String> keys,
Object... args) |
static <T> T |
execute(org.springframework.data.redis.core.script.RedisScript<T> script,
org.springframework.data.redis.serializer.RedisSerializer<?> argsSerializer,
org.springframework.data.redis.serializer.RedisSerializer<T> resultSerializer,
List<String> keys,
Object... args) |
static <T> T |
execute(org.springframework.data.redis.core.SessionCallback<T> session) |
static List<Object> |
executePipelined(org.springframework.data.redis.core.RedisCallback<?> action) |
static List<Object> |
executePipelined(org.springframework.data.redis.core.RedisCallback<?> action,
org.springframework.data.redis.serializer.RedisSerializer<?> resultSerializer) |
static List<Object> |
executePipelined(org.springframework.data.redis.core.SessionCallback<?> session) |
static List<Object> |
executePipelined(org.springframework.data.redis.core.SessionCallback<?> session,
org.springframework.data.redis.serializer.RedisSerializer<?> resultSerializer) |
static long |
exists(Collection<String> keys) |
static long |
exists(String... keys)
判断指定的 key 是否存在.
|
static boolean |
exists(String key)
判断 key 是否存在
|
static boolean |
expire(String key,
long timeout)
设置过期时间
|
static boolean |
expire(String key,
long timeout,
TimeUnit timeUnit)
设置过期时间
|
static boolean |
expireAt(String key,
Date date)
设置 key 的过期时间到指定的日期
|
static boolean |
expireAt(String key,
Instant expireAt) |
static String |
get(String key)
获取指定 key 的 value 值
|
static String |
getDel(String key)
获取指定 key 的 value 值,并将指定的 key 进行删除
|
static String |
getEx(String key,
long timeout)
获取指定 key 的 value 值,并对 key 设置指定的过期时间
|
static String |
getEx(String key,
long timeout,
TimeUnit timeUnit)
获取指定 key 的 value 值,并对 key 设置指定的过期时间
|
static org.springframework.data.redis.core.RedisTemplate<String,String> |
getRedisTemplate() |
static String |
getSet(String key,
String value)
获取指定的 key 的 value 值,并同时使用指定的 value 值进行覆盖操作
|
static Long |
hashDelete(String key,
String... fields)
|
static String |
hashGet(String key,
String field)
已过时。
|
static org.springframework.data.redis.core.HashOperations<String,String,String> |
hashOps() |
static void |
hashSet(String key,
String field,
String value)
|
static boolean |
hasKey(String key)
已过时。
|
static long |
hDel(String key,
String... fields)
删除指定 hash 的 fields
|
static boolean |
hExists(String key,
String field)
判断指定 hash 的 指定 field 是否存在
|
static String |
hGet(String key,
String field)
获取 hash 中的指定 field 对应的 value 值
|
static Map<String,String> |
hGetAll(String key)
获取 hash 中所有的 fields 和 values, 并已键值对的方式返回
|
static Long |
hIncrBy(String key,
String field)
对 hash 中指定的 field 进行自增
|
static long |
hIncrBy(String key,
String field,
long delta)
对 hash 中指定的 field 进行自增
若 field 不存在则,先设置为 0 再进行自增,若 hash 不存在则先创建 hash 再进行上述步骤
|
static double |
hIncrByFloat(String key,
String field,
double delta)
对 hash 中指定的 field 进行自增
若 field 不存在则,先设置为 0 再进行自增,若 hash 不存在则先创建 hash 再进行上述步骤
|
static Set<String> |
hKeys(String key)
返回 hash 中的所有 fields
|
static long |
hLen(String key)
返回 hash 中 fields 的数量
|
static List<String> |
hMGet(String key,
Collection<String> fields)
返回 hash 中指定 fields 的值集合
|
static List<String> |
hMGet(String key,
String... fields)
返回 hash 中指定 fields 的值集合
|
static void |
hSet(String key,
String field,
String value)
修改 hash 中的 field 的值,有则覆盖,无则添加
|
static void |
hSetNx(String key,
String field,
String value)
修改 hash 中的 field 的值,有则不进行操作,无则添加
|
static List<String> |
hVals(String key)
返回 hash 中的所有 values
|
static long |
incr(String key)
对 key 进行自增,自增步长为 1
|
static long |
incrAndExpire(String key,
long timeout)
对 key 进行自增 (步长为 1),并设置过期时间
|
static long |
incrBy(String key,
long delta)
对 key 进行自增,并指定自增步长, 当 key 不存在时先创建一个值为 0 的 key,再进行自增
|
static long |
incrByAndExpire(String key,
long delta,
long timeout)
对 key 进行自增并设置过期时间,指定自增步长, 当 key 不存在时先创建一个值为 0 的 key,再进行自增
|
static double |
incrByFloat(String key,
double delta) |
static Long |
increment(String key)
已过时。
|
static Long |
increment(String key,
long delta)
已过时。
|
static Long |
incrementAndExpire(String key,
long time)
|
static Long |
incrementAndExpire(String key,
long delta,
long time)
|
static Set<String> |
keys(String pattern)
获取所有符合指定表达式的 key
|
static String |
lIndex(String key,
long index)
获取指定 list 指定索引位置的元素
|
static List<String> |
listGet(String key)
已过时。
use lRange(key, 0, -1)
lRange(String, long, long) |
static String |
listIndex(String key,
long index)
已过时。
|
static Long |
listIndexOf(String key,
String val)
已过时。
|
static String |
listLeftPop(String key)
已过时。
|
static Long |
listLeftPush(String key,
String val)
|
static org.springframework.data.redis.core.ListOperations<String,String> |
listOps() |
static Long |
listRemove(String key,
long count,
String val)
已过时。
|
static Long |
listRemove(String key,
String val)
已过时。
|
static String |
listRightPop(String key)
已过时。
|
static Long |
listRightPush(String key,
String val)
|
static long |
listSet(String key,
List<String> list,
long time)
已过时。
|
static long |
listSize(String key)
已过时。
|
static long |
lLen(String key)
获取指定 list 的元素个数即长度
|
static String |
lPop(String key)
以原子方式返回并删除列表的第一个元素,例如列表包含元素 "a", "b", "c" LPOP 操作将返回 ”a“ 并将其删除,list 中元素变为 ”b“, "c"
|
static List<String> |
lPop(String key,
long count)
以原子方式返回并删除列表的多个元素
|
static Long |
lPos(String key,
String element)
该命令返回 list 匹配元素的索引。
|
static long |
lPush(String key,
List<String> elements)
将指定的值插入 list 的头部,若 list 不存在,则先指向创建一个空的 list
|
static long |
lPush(String key,
String... elements)
将指定的元素插入 list 的头部,若 list 不存在,则先指向创建一个空的 list
|
static List<String> |
lRange(String key,
long start,
long end)
获取 list 指定 offset 间的元素。
|
static long |
lRem(String key,
long count,
String value)
删除 list 中的元素
count > 0: 从 list 头部向尾部查找并删除 n 个和指定值相等的元素,n 为 count
count < 0: 从 list 尾部向头部查找并删除 n 个和指定值相等的元素,n 为 count 的绝对值
count = 0: 删除 list 中所有和指定值相等的元素
|
static void |
lSet(String key,
long index,
String value)
将 list 指定 index 位置的元素设置为当前值
|
static void |
lTrim(String key,
long start,
long end)
裁剪 list,只保留 start 到 end 之间的元素值,包含 start 和 end
|
static List<String> |
mGet(Collection<String> keys)
从指定的 keys 批量获取 values
|
static List<String> |
mGet(String... keys) |
static Map<String,String> |
mGetToMap(Collection<String> keys)
批量获取 keys 的值,并返回一个 map
|
static Map<String,String> |
mGetToMap(String... keys) |
static List<String> |
multiGet(Collection<String> keys)
已过时。
|
static void |
publish(String channel,
byte[] message)
Publish 一条消息
|
static void |
publish(String channel,
String message)
Publish 一条消息
|
static String |
rPop(String key)
以原子方式返回并删除列表的最后一个元素。
|
static List<String> |
rPop(String key,
long count)
从 list 尾部,以原子方式返回并删除列表中指定数量的元素。
|
static long |
rPush(String key,
List<String> values)
将指定的值插入 list 的尾部,若 list 不存在,则先指向创建一个空的 list
|
static long |
rPush(String key,
String... values)
将指定的值插入 list 的尾部,若 list 不存在,则先指向创建一个空的 list
|
static long |
sAdd(String key,
List<String> members)
将指定的 member 添加到 Set 中,如果 Set 中已有该 member 则忽略。
|
static long |
sAdd(String key,
String... members)
将指定的 member 添加到 Set 中,如果 Set 中已有该 member 则忽略。
|
static org.springframework.data.redis.core.Cursor<String> |
scan(org.springframework.data.redis.core.ScanOptions scanOptions)
使用 Cursor 遍历指定规则的 keys
|
static org.springframework.data.redis.core.Cursor<String> |
scan(String patten)
使用 Cursor 遍历指定规则的 keys
|
static org.springframework.data.redis.core.Cursor<String> |
scan(String patten,
long count)
使用 Cursor 遍历指定规则的 keys
|
static long |
sCard(String key)
返回 Set 中的元素数,如果 set 不存在则返回 0
|
static void |
set(String key,
String value)
设置 value for key
|
static void |
set(String key,
String val,
Instant instant)
|
static void |
set(String key,
String value,
long timeout)
设置 value for key, 同时为其设置过期时间
|
static void |
set(String key,
String value,
long timeout,
TimeUnit timeUnit)
设置 value for key, 同时为其设置过期时间
|
static Long |
setAdd(String key,
String... values)
|
static void |
setEx(String key,
String value,
long timeout)
设置 value for key, 同时为其设置过期时间
|
static void |
setEx(String key,
String value,
long timeout,
TimeUnit timeUnit)
设置 value for key, 同时为其设置过期时间
|
static void |
setExAt(String key,
String value,
Instant expireTime)
设置 value for key, 同时为其设置其在指定时间过期
|
static boolean |
setIfAbsent(String key,
String value)
|
static boolean |
setIfAbsent(String key,
String value,
long time)
|
static boolean |
setNx(String key,
String value)
当 key 不存在时,进行 value 设置,当 key 存在时不执行操作
|
static boolean |
setNxEx(String key,
String value,
long timeout)
当 key 不存在时,进行 value 设置并添加过期时间,当 key 存在时不执行操作
|
static boolean |
setNxEx(String key,
String value,
long timeout,
TimeUnit timeUnit)
当 key 不存在时,进行 value 设置并添加过期时间,当 key 存在时不执行操作
|
static org.springframework.data.redis.core.SetOperations<String,String> |
setOps() |
static String |
setPop(String key)
已过时。
|
static void |
setRedisTemplate(org.springframework.data.redis.core.RedisTemplate<String,String> redisTemplate) |
static Long |
setRemove(String key,
String... values)
|
static Long |
setSize(String key)
已过时。
|
static boolean |
sIsMember(String key,
String value)
判断指定的值是否是 Set 中的元素
Time complexity O(1)
|
static Set<String> |
sMembers(String key)
获取 Set 中的所有元素
Time complexity O(N)
|
static Map<Object,Boolean> |
sMIsMember(String key,
String... values)
判断指定的值是否是 Set 中的元素
Time complexity O(N)
|
static String |
sPop(String key)
随机从 Set 中删除一个元素,并返回它,如果 Set 为空,则返回 null
Time complexity O(1)
|
static String |
sRandMember(String key)
随机从 Set 中返回一个元素,但不删除,如果 Set 为空,则返回 null
Time complexity O(1)
|
static Set<String> |
sRandMember(String key,
long count)
随机从 Set 中返回 count 个元素,但不删除,如果 Set 为空,则返回 null
Time complexity O(1)
|
static long |
sRem(String key,
String... members)
从 Set 中删除指定的 member,如果给的值不是 Set 的 member 则不进行操作
Time complexity O(1)
|
static org.springframework.data.redis.core.Cursor<String> |
sScan(String key,
org.springframework.data.redis.core.ScanOptions scanOptions)
使用 Cursor 遍历指定 Set 中的所有元素
|
static org.springframework.data.redis.core.StreamOperations<String,String,String> |
streamOps() |
static long |
ttl(String key)
TTL 命令返回
EXPIRE 命令设置的剩余生存时间(以秒为单位).。 |
static org.springframework.data.redis.core.ValueOperations<String,String> |
valueOps() |
static long |
xAck(String key,
String group,
org.springframework.data.redis.connection.stream.RecordId... ids) |
static long |
xAck(String key,
String group,
String... ids)
XACK key group ID [ID ...]
|
static org.springframework.data.redis.connection.stream.RecordId |
xAdd(org.springframework.data.redis.connection.stream.MapRecord<String,String,String> mapRecord,
org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions xAddOptions) |
static org.springframework.data.redis.connection.stream.RecordId |
xAdd(String key,
Map<String,String> content)
XADD key ID field string [field string ...]
|
static org.springframework.data.redis.connection.stream.RecordId |
xAdd(String key,
Map<String,String> content,
org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions xAddOptions) |
static long |
xDel(String key,
org.springframework.data.redis.connection.stream.RecordId... ids) |
static long |
xDel(String key,
String... ids)
XDEL key ID [ID ...]
|
static String |
xGroupCreate(String key,
String groupName) |
static String |
xGroupCreate(String key,
String groupName,
org.springframework.data.redis.connection.stream.ReadOffset readOffset,
boolean makeStream)
XGROUP CREATE
|
static long |
xLen(String key)
XLEN key
|
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xRange(String key,
org.springframework.data.domain.Range<String> range)
XRANGE key start end COUNT count
|
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xRange(String key,
org.springframework.data.domain.Range<String> range,
org.springframework.data.redis.connection.RedisZSetCommands.Limit limit) |
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xRead(org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
XREAD [COUNT count] [BLOCK milliseconds] STREAMS key [key ...]
|
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xRead(org.springframework.data.redis.connection.stream.StreamReadOptions streamReadOptions,
org.springframework.data.redis.connection.stream.StreamOffset<String>... streams) |
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xReadGroup(org.springframework.data.redis.connection.stream.Consumer consumer,
org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
XREADGROUP GROUP group consumer [COUNT count] [BLOCK milliseconds] [NOACK] STREAMS
key [key ...] id [id ...]
|
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xReadGroup(org.springframework.data.redis.connection.stream.Consumer consumer,
org.springframework.data.redis.connection.stream.StreamReadOptions streamReadOptions,
org.springframework.data.redis.connection.stream.StreamOffset<String>... streams) |
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xReadGroup(String group,
String consumer,
org.springframework.data.redis.connection.stream.StreamOffset<String>... streams) |
static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> |
xReadGroup(String group,
String consumer,
org.springframework.data.redis.connection.stream.StreamReadOptions streamReadOptions,
org.springframework.data.redis.connection.stream.StreamOffset<String>... streams) |
static boolean |
zAdd(String key,
double score,
String member)
添加拥有指定 score 的 member 到 Sorted Set 中。
|
static long |
zAdd(String key,
Map<String,Double> scoreMembers)
批量添加拥有指定 score 的 member 到 Sorted Set 中。
|
static long |
zCard(String key)
返回 Sorted Set 的元素数量,若 key 不存在则返回 0
Time complexity O(1)
|
static double |
zIncrBy(String key,
double increment,
String member)
如果 member 存在于 Sorted Set 中,则对其 score 和 increment 进行相加运算,并重排序。
|
static org.springframework.data.redis.core.ZSetOperations.TypedTuple<String> |
zPopMax(String key)
返回并删除 Sorted Set 中分数最高的那个元素
Time complexity O(log(N)) with N being the number of elements in the sorted set
|
static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> |
zPopMax(String key,
long count)
返回并删除 Sorted Set 中分数最高的 n 个元素
Time complexity O(log(N)) with N being the number of elements in the sorted set
|
static org.springframework.data.redis.core.ZSetOperations.TypedTuple<String> |
zPopMin(String key)
返回并删除 Sorted Set 中分数最低的那个元素
Time complexity O(log(N)) with N being the number of elements in the sorted set
|
static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> |
zPopMin(String key,
long count)
返回并删除 Sorted Set 中分数最低的 n 个元素
Time complexity O(log(N)) with N being the number of elements in the sorted set
|
static String |
zRandMember(String key)
随机从 Sorted Set 中返回一个 member
Time complexity O(N) where N is the number of elements returned
|
static Set<String> |
zRange(String key,
long start,
long end)
返回 Sorted Set 中指定索引范围内的 member.
|
static Set<String> |
zRangeByScore(String key,
double min,
double max)
返回 Sorted Set 中指定 score 间的所有元素(包括 score 等于 min 和 max 的元素)
Time complexity O(log(N)+M) with N being the number of elements in the sorted set
and M the number of elements being returned.
|
static Set<String> |
zRangeByScore(String key,
double min,
double max,
long offset,
long count)
返回 Sorted Set 中指定 score 间的所有元素(包括 score 等于 min 和 max 的元素)
|
static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> |
zRangeByScoreWithScores(String key,
double min,
double max)
返回 Sorted Set 中指定 score 间的所有元素和其分数(包括 score 等于 min 和 max 的元素)
|
static Long |
zRank(String key,
String member)
返回 member 的排名(索引)。
|
static long |
zRem(String key,
String... members)
从 Sorted Set 中删除指定的 member。
|
static Set<String> |
zRevRange(String key,
long start,
long end)
返回 Sorted Set 中 index 在 start 和 end 之前的所有成员(包括 start 和 end)。
|
static Set<String> |
zRevRangeByScore(String key,
double min,
double max)
返回 Sorted Set 中分数在 min 和 max 之前的所有成员(包括 min 和 max)。
|
static Double |
zScore(String key,
String member)
返回 Sorted Set 中指定 member 的分数。
|
static Boolean |
zSetAdd(String key,
String value,
double score)
|
static org.springframework.data.redis.core.ZSetOperations<String,String> |
zSetOps() |
static String |
zSetRandom(String key)
已过时。
|
static Set<String> |
zSetRange(String key,
int start,
int end)
|
static Set<String> |
zSetRangeByScore(String key,
double min,
double max)
|
static Long |
zSetRank(String key,
String value)
|
static Long |
zSetRemove(String key,
String... values)
|
static Set<String> |
zSetReverseRange(String key,
int start,
int end)
|
static Set<String> |
zSetReverseRangeByScore(String key,
double min,
double max)
|
static Long |
zSetSize(String key)
已过时。
|
public static final RedisHelper INSTANCE
public static org.springframework.data.redis.core.RedisTemplate<String,String> getRedisTemplate()
public static void setRedisTemplate(org.springframework.data.redis.core.RedisTemplate<String,String> redisTemplate)
public static org.springframework.data.redis.core.HashOperations<String,String,String> hashOps()
public static org.springframework.data.redis.core.ValueOperations<String,String> valueOps()
public static org.springframework.data.redis.core.StreamOperations<String,String,String> streamOps()
@Deprecated public static boolean hasKey(String key)
@Deprecated public static boolean delete(String key)
del(String)@Deprecated public static long delete(Collection<String> keys)
del(Collection)public static boolean del(String key)
key - 要删除的 keypublic static long del(String... keys)
keys - 要删除的 key 数组public static long del(Collection<String> keys)
public static boolean exists(String key)
key - 待判断的 keytrue , 否则返回 falsepublic static long exists(String... keys)
keys - 待判断的数组public static long exists(Collection<String> keys)
public static boolean expire(String key, long timeout)
key - 待修改过期时间的 keytimeout - 过期时长,单位 秒public static boolean expire(String key, long timeout, TimeUnit timeUnit)
key - 待修改过期时间的 keytimeout - 时长timeUnit - 时间单位public static boolean expireAt(String key, Date date)
key - 待修改过期时间的 keydate - 过期时间public static Set<String> keys(String pattern)
pattern - 表达式public static long ttl(String key)
EXPIRE 命令设置的剩余生存时间(以秒为单位).。
时间复杂度: O(1)
key - 待查询的 keypublic static org.springframework.data.redis.core.Cursor<String> scan(org.springframework.data.redis.core.ScanOptions scanOptions)
scanOptions - scan 的配置public static org.springframework.data.redis.core.Cursor<String> scan(String patten)
patten - key 的规则public static org.springframework.data.redis.core.Cursor<String> scan(String patten, long count)
patten - key 的规则count - 一次扫描获取的 key 数量, 默认为 10public static long decr(String key)
key - keydecrBy(String, long)public static long decrBy(String key, long delta)
key - keydelta - 自减步长public static String get(String key)
key - 指定的 keypublic static String getDel(String key)
key - 指定的 keypublic static String getEx(String key, long timeout)
key - 指定的 keytimeout - 过期时间,单位时间秒public static String getEx(String key, long timeout, TimeUnit timeUnit)
key - 指定的 keytimeout - 过期时间,单位时间秒timeUnit - 时间单位public static String getSet(String key, String value)
key - 指定的 keyvalue - 新的 value 值public static long incr(String key)
key - 需要自增的 keyincrBy(String, long)public static long incrAndExpire(String key, long timeout)
public static long incrBy(String key, long delta)
key - 需要自增的 keydelta - 自增的步长public static long incrByAndExpire(String key, long delta, long timeout)
key - 需要自增的 keydelta - 自增的步长timeout - 过期时间(单位:秒)public static double incrByFloat(String key, double delta)
incrBy(String, long)@Deprecated public static Long increment(String key)
incr(String)@Deprecated public static Long increment(String key, long delta)
incrBy(String, long)@Deprecated public static Long incrementAndExpire(String key, long time)
@Deprecated public static Long incrementAndExpire(String key, long delta, long time)
public static List<String> mGet(Collection<String> keys)
keys - keyspublic static List<String> mGet(String... keys)
mGet(Collection)public static Map<String,String> mGetToMap(Collection<String> keys)
keys - keyspublic static Map<String,String> mGetToMap(String... keys)
mGetToMap(Collection)@Deprecated public static List<String> multiGet(Collection<String> keys)
mGet(Collection)public static void set(String key, String value)
key - 指定的 keyvalue - 值public static void set(String key, String value, long timeout)
key - keyvalue - valuetimeout - 过期时间 单位:秒setEx(String, String, long)public static void set(String key, String value, long timeout, TimeUnit timeUnit)
key - keyvalue - valuetimeout - 过期时间 单位:秒timeUnit - 过期时间单位setEx(String, String, long,TimeUnit)@Deprecated public static void set(String key, String val, Instant instant)
key - keyval - valinstant - 在指定时间过期public static void setEx(String key, String value, long timeout)
key - 指定的 keyvalue - 值timeout - 过期时间public static void setEx(String key, String value, long timeout, TimeUnit timeUnit)
key - 指定的 keyvalue - 值timeout - 过期时间timeUnit - 时间单位public static void setExAt(String key, String value, Instant expireTime)
key - keyvalue - valueexpireTime - 在指定时间过期public static boolean setNx(String key, String value)
key - keyvalue - value@Deprecated public static boolean setIfAbsent(String key, String value)
key - keyvalue - valpublic static boolean setNxEx(String key, String value, long timeout)
key - keyvalue - valuetimeout - 过期时间public static boolean setNxEx(String key, String value, long timeout, TimeUnit timeUnit)
key - keyvalue - valuetimeout - 过期时间timeUnit - 时间单位@Deprecated public static boolean setIfAbsent(String key, String value, long time)
key - keyvalue - 值time - 过期时间, 单位 秒public static long hDel(String key, String... fields)
key - hash 的 keyfields - hash 元素的 field 集合public static boolean hExists(String key, String field)
key - hash 的 keyfield - 元素的 fieldtrue, 否则返回 falsepublic static String hGet(String key, String field)
key - hash 的 keyfield - 元素的 fieldpublic static Map<String,String> hGetAll(String key)
key - hash 的 keypublic static long hIncrBy(String key, String field, long delta)
key - keyfield - fielddelta - 自增步长public static double hIncrByFloat(String key, String field, double delta)
key - keyfield - fielddelta - 自增步长public static Set<String> hKeys(String key)
key - hash 的 keypublic static long hLen(String key)
key - hash 的 keypublic static List<String> hMGet(String key, Collection<String> fields)
key - hash 的 keypublic static List<String> hMGet(String key, String... fields)
key - hash 的 keypublic static void hSet(String key, String field, String value)
key - hash 的 keyfield - fieldvalue - value@Deprecated public static void hashSet(String key, String field, String value)
public static void hSetNx(String key, String field, String value)
key - hash 的 keyfield - fieldvalue - valuepublic static List<String> hVals(String key)
key - hash 的 key@Deprecated public static String hashGet(String key, String field)
hGet(String, String)key - keyfield - field@Deprecated public static Long hashDelete(String key, String... fields)
key - keyfields - 字段public static String lIndex(String key, long index)
key - list 的 keyindex - 索引位置,0 表示第一个元素,负数索引用于指定从尾部开始计数,-1 表示最后一个元素,-2 倒数第二个@Deprecated public static String listIndex(String key, long index)
lIndex(String, long)public static long lLen(String key)
key - list 的 key@Deprecated public static long listSize(String key)
lLen(String)public static String lPop(String key)
key - list 的 keypublic static List<String> lPop(String key, long count)
key - list 的 keycount - 弹出的个数@Deprecated public static String listLeftPop(String key)
lPop(String)public static Long lPos(String key, String element)
key - list 的 keyelement - 查找的元素@Deprecated public static Long listIndexOf(String key, String val)
lPos(String, String)public static long lPush(String key, String... elements)
key - list 的 keyelements - 插入的元素public static long lPush(String key, List<String> elements)
key - list 的 keyelements - 插入的元素@Deprecated public static Long listLeftPush(String key, String val)
key - keyval - valpublic static List<String> lRange(String key, long start, long end)
key - list 的 keystart - begin offset, 从 0 开始,0 表示列表第一个元素,也可以为负数,表示从 list 末尾开始的偏移量, -1
是列表最后第一个元素end - end offset,值规则 同 start@Deprecated public static List<String> listGet(String key)
lRange(String, long, long)public static long lRem(String key, long count, String value)
key - list 的 keycount - 删除的数量以及规则value - 待删除的元素值@Deprecated public static Long listRemove(String key, String val)
lRem(String, long, String)@Deprecated public static Long listRemove(String key, long count, String val)
count - 删除多少个@Deprecated public static long listSet(String key, List<String> list, long time)
key - keylist - list 值time - 过期时间public static void lSet(String key, long index, String value)
key - list 的 keyindex - 索引位置,0 表示第一个元素,负数索引用于指定从尾部开始计数,-1 表示最后一个元素,-2 倒数第二个value - 值public static void lTrim(String key, long start, long end)
key - list 的 keystart - 开始索引位置,0 表示第一个元素,负数索引用于指定从尾部开始计数,-1 表示最后一个元素,-2 倒数第二个end - 结束的索引位置public static String rPop(String key)
例如 list 包含元素 "a"、"b"、"c", RPOP 操作将返回 ”c“ 并将其删除,list 中元素变为 ”a“, "b"
key - list 的 keypublic static List<String> rPop(String key, long count)
key - list 的 keycount - 待弹出的元素数量public static long rPush(String key, String... values)
key - list 的 keyvalues - 插入的元素public static long rPush(String key, List<String> values)
key - list 的 keyvalues - 插入的元素@Deprecated public static Long listRightPush(String key, String val)
@Deprecated public static String listRightPop(String key)
rPop(String)public static long sAdd(String key, String... members)
Time complexity O(1)
key - Set 的 keymembers - 添加的成员public static long sAdd(String key, List<String> members)
Time complexity O(1)
key - Set 的 keymembers - 添加的成员@Deprecated public static Long setAdd(String key, String... values)
public static long sCard(String key)
key - Set 的 key@Deprecated public static Long setSize(String key)
sCard(String)public static boolean sIsMember(String key, String value)
Time complexity O(1)
key - Set 的 keyvalue - 待判断的值true, 否则返回falsepublic static Set<String> sMembers(String key)
Time complexity O(N)
key - Set 的 keypublic static Map<Object,Boolean> sMIsMember(String key, String... values)
Time complexity O(N)
key - Set 的 keyvalues - 待判断的值集合public static String sPop(String key)
Time complexity O(1)
key - Set 的 key@Deprecated public static String setPop(String key)
sPop(String)public static String sRandMember(String key)
Time complexity O(1)
key - Set 的 keypublic static Set<String> sRandMember(String key, long count)
Time complexity O(1)
key - Set 的 keycount - 随机返回的元素数量public static long sRem(String key, String... members)
Time complexity O(1)
key - Set 的 keymembers - 待删除的成员@Deprecated public static Long setRemove(String key, String... values)
public static org.springframework.data.redis.core.Cursor<String> sScan(String key, org.springframework.data.redis.core.ScanOptions scanOptions)
scanOptions - scan 的配置public static boolean zAdd(String key, double score, String member)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keyscore - 分数member - 成员public static long zAdd(String key, Map<String,Double> scoreMembers)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keyscoreMembers - 成员和分数的键值对@Deprecated public static Boolean zSetAdd(String key, String value, double score)
public static long zCard(String key)
Time complexity O(1)
key - Sorted Set 的 key@Deprecated public static Long zSetSize(String key)
zCard(String)public static double zIncrBy(String key, double increment, String member)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keyincrement - 增长步长,可以为负数member - 成员public static org.springframework.data.redis.core.ZSetOperations.TypedTuple<String> zPopMax(String key)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keypublic static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> zPopMax(String key, long count)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keycount - 弹出的个数public static org.springframework.data.redis.core.ZSetOperations.TypedTuple<String> zPopMin(String key)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keypublic static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> zPopMin(String key, long count)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keycount - 弹出的个数public static String zRandMember(String key)
Time complexity O(N) where N is the number of elements returned
key - Sorted Set 的 Key@Deprecated public static String zSetRandom(String key)
zRandMember(String)public static Set<String> zRange(String key, long start, long end)
Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
key - the key to querystart - the minimum indexend - the maximum indexpublic static Set<String> zRangeByScore(String key, double min, double max)
Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned.
key - the key to querymin - minimum scoremax - maximum scorepublic static Set<String> zRangeByScore(String key, double min, double max, long offset, long count)
key - the key to querymin - minimum scoremax - maximum scoreoffset - 偏移量count - 获取的元素数public static Set<org.springframework.data.redis.core.ZSetOperations.TypedTuple<String>> zRangeByScoreWithScores(String key, double min, double max)
key - the key to querymin - minimum scoremax - maximum scorepublic static Long zRank(String key, String member)
Time complexity O(log(N))
key - Sorted Set 的 keymember - 成员public static long zRem(String key, String... members)
Time complexity O(log(N)) with N being the number of elements in the sorted set
key - Sorted Set 的 keymembers - 待删除的成员@Deprecated public static Long zSetRemove(String key, String... values)
@Deprecated public static Long zSetRank(String key, String value)
public static Set<String> zRevRange(String key, long start, long end)
与默认的排序规则相反,元素的顺序是按分数从高到低进行的,具有相同分数的元素以相反的字典顺序排序
Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements returned.
key - the key to querystart - the minimum indexend - the maximum indexpublic static Set<String> zRevRangeByScore(String key, double min, double max)
与默认的排序规则相反,元素的顺序是按分数从高到低进行的。
具有相同分数的元素以相反的字典顺序返回.
Time complexity O(log(N)+M) with N being the number of elements in the sorted set and M the number of elements being returned.
key - the key to querymin - minimum scoremax - maximum scorepublic static Double zScore(String key, String member)
Time complexity: O(1)
key - Sorted Set Keymember - Sorted Set Member@Deprecated public static Set<String> zSetRange(String key, int start, int end)
@Deprecated public static Set<String> zSetReverseRange(String key, int start, int end)
@Deprecated public static Set<String> zSetRangeByScore(String key, double min, double max)
@Deprecated public static Set<String> zSetReverseRangeByScore(String key, double min, double max)
public static <T> T execute(org.springframework.data.redis.core.RedisCallback<T> action)
action - redis 操作@Nullable
public static <T> T execute(org.springframework.data.redis.core.RedisCallback<T> action,
boolean exposeConnection)
@Nullable
public static <T> T execute(org.springframework.data.redis.core.RedisCallback<T> action,
boolean exposeConnection,
boolean pipeline)
public static <T> T execute(org.springframework.data.redis.core.SessionCallback<T> session)
public static <T> T execute(org.springframework.data.redis.core.script.RedisScript<T> script,
List<String> keys,
Object... args)
public static <T> T execute(org.springframework.data.redis.core.script.RedisScript<T> script,
org.springframework.data.redis.serializer.RedisSerializer<?> argsSerializer,
org.springframework.data.redis.serializer.RedisSerializer<T> resultSerializer,
List<String> keys,
Object... args)
@Deprecated public static Object evalLua(String lua, List<String> key, Object... argv)
public static List<Object> executePipelined(org.springframework.data.redis.core.SessionCallback<?> session)
public static List<Object> executePipelined(org.springframework.data.redis.core.SessionCallback<?> session, @Nullable org.springframework.data.redis.serializer.RedisSerializer<?> resultSerializer)
public static List<Object> executePipelined(org.springframework.data.redis.core.RedisCallback<?> action)
public static List<Object> executePipelined(org.springframework.data.redis.core.RedisCallback<?> action, @Nullable org.springframework.data.redis.serializer.RedisSerializer<?> resultSerializer)
public static void publish(String channel, String message)
channel - 渠道message - 消息public static void publish(String channel, byte[] message)
channel - 渠道message - 消息public static long xAck(String key, String group, String... ids)
key - key of streamgroup - consume groupids - record idspublic static long xAck(String key, String group, org.springframework.data.redis.connection.stream.RecordId... ids)
public static org.springframework.data.redis.connection.stream.RecordId xAdd(String key, Map<String,String> content)
key - key of streamcontent - record contentpublic static org.springframework.data.redis.connection.stream.RecordId xAdd(String key, Map<String,String> content, org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions xAddOptions)
public static org.springframework.data.redis.connection.stream.RecordId xAdd(org.springframework.data.redis.connection.stream.MapRecord<String,String,String> mapRecord, org.springframework.data.redis.connection.RedisStreamCommands.XAddOptions xAddOptions)
public static long xDel(String key, String... ids)
key - key of streamids - record idspublic static long xDel(String key, org.springframework.data.redis.connection.stream.RecordId... ids)
public static String xGroupCreate(String key, String groupName, org.springframework.data.redis.connection.stream.ReadOffset readOffset, boolean makeStream)
key - key of streamgroupName - group namepublic static long xLen(String key)
key - key of streampublic static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xRange(String key, org.springframework.data.domain.Range<String> range)
key - key of streamrange - start and endpublic static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xRange(String key, org.springframework.data.domain.Range<String> range, org.springframework.data.redis.connection.RedisZSetCommands.Limit limit)
public static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xRead(org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
public static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xRead(org.springframework.data.redis.connection.stream.StreamReadOptions streamReadOptions, org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
public static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xReadGroup(org.springframework.data.redis.connection.stream.Consumer consumer, org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
public static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xReadGroup(org.springframework.data.redis.connection.stream.Consumer consumer, org.springframework.data.redis.connection.stream.StreamReadOptions streamReadOptions, org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
public static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xReadGroup(String group, String consumer, org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
public static List<org.springframework.data.redis.connection.stream.MapRecord<String,String,String>> xReadGroup(String group, String consumer, org.springframework.data.redis.connection.stream.StreamReadOptions streamReadOptions, org.springframework.data.redis.connection.stream.StreamOffset<String>... streams)
Copyright © 2023. All rights reserved.