ChatGPT 可用网址,仅供交流学习使用,如对您有所帮助,请收藏并推荐给需要的朋友。
https://ckai.xyz
sets
A Redis set is an unordered collection of unique strings (members).
无序的字符串集合
相关命令:
- SADD
SADD key member [member ...]
- SREM
SREM key member [member ...]
- SMEMBERS
Returns all the members of the set value stored at key.
- SISMEMBER
SISMEMBER key member
Returns if member is a member of the set stored at key.1 if the element is a member of the set.0 if the element is not a member of the set, or if key does not exist.
- SMISMEMBER
Returns whether each member is a member of the set stored at key.
SMISMEMBER key member [member ...]
-
SINTER
SINTER key [key ...]
Returns the members of the set resulting from the intersection of all the given sets.求交集
- SCARD
Returns the set cardinality (number of elements) of the set stored at key.
计算集合中的基数,其实就是set中元素的总数量,因为set是没有重复的。
- SDIFF
SDIFF key [key ...]
Returns the members of the set resulting from the difference between the first set and all the successive sets.
返回第一个集合和剩余集合的差集,是指包含在第一个集合中但不包含在其他集合中的元素。
- SDIFFSTORE
SDIFFSTORE destination key [key ...]
This command is equal to SDIFF, but instead of returning the resulting set, it is stored in destination.
- SINTERCARD
This command is similar to SINTER, but instead of returning the result set, it returns just the cardinality of the result.
返回:结果交集中的元素数
- SINTERSTORE
This command is equal to SINTER, but instead of returning the resulting set, it is stored in destination.
- SMOVE
将 member 元素从 source 集合移动到 destination 集合
- SPOP
移除并返回集合中的一个随机元素
- SSCAN
Redis Sscan 命令用于迭代集合中键的元素。
SADD myset1 "hello"
SADD myset1 "hi"
SADD myset1 "bar"
sscan myset1 0 match h*
1) "0"
2) 1) "hello"
2) "h1"
- SUNION
- SUNIONSTORE