Redis3-集合
集合
- List
- Hash
- Set
- sorted_set
List
双向链表

命令
-
LPUSH k1 a b c d ePrepend one or multiple values to a list -
RPUSH k2 e d c b aAppend one or multiple values to a list -
LPOP k1Remove and get the first element in a list -
RPOP k1Remove and get the last element in a list -
LRANGE k1 0 -1Get a range of elements from a list -
LINDEX LSET类似数组操作
LREM k3 2 aRemove elements from a listLINSERT k3 after 6 a* Insert an element before or after another element in a list*

9. BLPOP ooxx 0 Remove and get the first element in a list, or block until one is available 阻塞队列FIFO
LTRIM k4 2 -2删除首尾 Trim a list to the specified range
Hash

命令
业务场景:微博点赞,数量增加;收藏、详情页
SET

SRANDMEMBER k4 10 count为整数:取出一个去重的结果集(不能超过已有集)负数:取出一个带重复的结果集,一定满足你要的数量
业务场景:抽奖
SPOP k4 满足抽到后取出,不能重复抽
sorted_set
有序Set集合

排序
因此,除了元素本身以外,你需要有分值这个维度,用来排序。如果分值相同,则按照名称字典序排列。

命令

ZUNIONSTORE Add multiple sorted sets and store the resulting sorted set in a new key
排序原理
底层结构:skip list 跳表 类平衡树 参考 ConcurrentSkipListMap

本文来自博客园,作者:gary2048,转载请注明原文链接:https://www.cnblogs.com/zhoum/p/15170820.html

浙公网安备 33010602011771号