String 整数,浮点数或者字符串
一个key对应一个value.
二进制安全 : 可以存储任何数据,比如图片或序列化的对象
MAX : 512MB
set key value
get key
Hash Map
一个key对应着一个键值对集合
•
适合用于存储对象。
hmset key field1 value field2 value
hmget key field
List
一个key对应着一个值的集合
•
按照插入顺序排序
•
列表最多可存储 232 - 1 元素 (4294967295, 每个列表可存储40多亿)。
•
index 从0开始, len从1 开始.
B 表示阻塞
L 表示从头部操作
R 表示从尾部操作
X 表示快速,不检查是否存在
•
BLMOVE
•
BLPOP
•
BRPOP
•
BRPOPLPUSH
•
LINDEX
•
LINSERT
•
LLEN
•
LMOVE
•
LMOVE mylist myotherlist RIGHT LEFT 从list1的尾巴拿一个元素放到list2的头
•
LPUSH
•
lpush key value 栈的push操作,插在头上,新push的元素的index是0
•
LPOP
•
LPOS
•
lpos key element [rank 从第几个结果开始输出] [count 输出几个结果] [maxlen 每次循环找到第几个元素(长度就是从1开始了)]
•
LSET
•
LPUSHX
•
LRANGE
•
例 : lrange key 0 -1
•
LREM
•
lrem key count element 删除. 从头开始
•
LTRIM
•
ltrim key start stop 删除范围外的, 左闭右闭
•
RPOP
•
RPOPLPUSH
•
RPUSH
•
RPUSHX
127.0.0.1:6379> lpush list 1
(integer) 1
127.0.0.1:6379> lpush list 2
(integer) 2
127.0.0.1:6379> lpush list 3
(integer) 3
127.0.0.1:6379> lrange list 0 10
1) "3"
2) "2"
3) "1"
127.0.0.1:6379> lindex list 0
"3"
127.0.0.1:6379> lindex list 2
"1"
Set 集合
Redis 的 Set 是 string 类型的无序集合。
集合是通过哈希表实现的,所以添加,删除,查找的复杂度都是 O(1)。
集合中最大的成员数为 232 - 1(4294967295, 每个集合可存储40多亿个成员)。
•
SADD key member [member ...]Add one or more members to a set
•
SCARD keyGet the number of members in a set
•
SDIFF key [key ...]Subtract multiple sets
•
在第一个key里不在右边的所有元素
•
SDIFFSTORE destination key [key ...]Subtract multiple sets and store the resulting set in a key
•
SINTER key [key ...]Intersect multiple sets
•
SINTERSTORE destination key [key ...]Intersect multiple sets and store the resulting set in a key
•
SISMEMBER key memberDetermine if a given value is a member of a set
•
SMISMEMBER key member [member ...]Returns the membership associated with the given elements for a set
•
是的话返回1 不是返回0
•
SMEMBERS keyGet all the members in a set
•
SMOVE source destination memberMove a member from one set to another
•
操作的聚合,没别的
•
SPOP key [count]Remove and return one or multiple random members from a set
•
随机弹出
•
SRANDMEMBER key [count]Get one or multiple random members from a set
•
随机获取
•
SREM key member [member ...]Remove one or more members from a set
•
删除
•
SUNION key [key ...]Add multiple sets
•
集合合并起来,只是返回一个结果,不对keys做更改
•
SUNIONSTORE destination key [key ...]Add multiple sets and store the resulting set in a key
•
SSCAN key cursor [MATCH pattern] [COUNT count]Incrementally iterate Set elements
Zset 有序集合
使用跳跃表实现
Redis zset 和 set 一样也是string类型元素的集合,且不允许重复的成员。
不同的是每个元素都会关联一个double类型的分数。redis正是通过分数来为集合中的成员进行从小到大的排序。
zset的成员是唯一的,但分数(score)却可以重复。
•
ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]Add one or more members to a sorted set, or update its score if it already exists
•
ZCARD keyGet the number of members in a sorted set
•
ZINCRBY key increment memberIncrement the score of a member in a sorted set
•
BZPOPMIN key [key ...] timeoutRemove and return the member with the lowest score from one or more sorted sets, or block until one is available
•
BZPOPMAX key [key ...] timeoutRemove and return the member with the highest score from one or more sorted sets, or block until one is available
•
ZCOUNT key min maxCount the members in a sorted set with scores within the given values
•
ZDIFF numkeys key [key ...] [WITHSCORES]Subtract multiple sorted sets
•
ZDIFFSTORE destination numkeys key [key ...]Subtract multiple sorted sets and store the resulting sorted set in a new key
•
ZINTER numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]Intersect multiple sorted sets
•
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]Intersect multiple sorted sets and store the resulting sorted set in a new key
•
ZLEXCOUNT key min maxCount the number of members in a sorted set between a given lexicographical range
•
ZPOPMAX key [count]Remove and return members with the highest scores in a sorted set
•
ZPOPMIN key [count]Remove and return members with the lowest scores in a sorted set
•
ZRANGE key start stop [WITHSCORES]Return a range of members in a sorted set, by index
•
ZRANGEBYLEX key min max [LIMIT offset count]Return a range of members in a sorted set, by lexicographical range
•
ZREVRANGEBYLEX key max min [LIMIT offset count]Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
•
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]Return a range of members in a sorted set, by score
•
ZRANK key memberDetermine the index of a member in a sorted set
•
ZREM key member [member ...]Remove one or more members from a sorted set
•
ZREMRANGEBYLEX key min maxRemove all members in a sorted set between the given lexicographical range
•
ZREMRANGEBYRANK key start stopRemove all members in a sorted set within the given indexes
•
ZREMRANGEBYSCORE key min maxRemove all members in a sorted set within the given scores
•
ZREVRANGE key start stop [WITHSCORES]Return a range of members in a sorted set, by index, with scores ordered from high to low
•
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]Return a range of members in a sorted set, by score, with scores ordered from high to low
•
ZREVRANK key memberDetermine the index of a member in a sorted set, with scores ordered from high to low
•
ZSCORE key memberGet the score associated with the given member in a sorted set
•
ZUNION numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] [WITHSCORES]Add multiple sorted sets
•
ZMSCORE key member [member ...]Get the score associated with the given members in a sorted set
•
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX]Add multiple sorted sets and store the resulting sorted set in a new key
•
ZSCAN key cursor [MATCH pattern] [COUNT count]Incrementally iterate sorted sets elements and associated scores
评论区