简单归纳整理一下Redis五种数据数据结构的常用命令。
String
set key value [ex seconds] [px milliseconds] [nx | xx]
setnx key value
get key
del key [key …]
mset key value [key value …]
mget key [key …]
incr key
decr key
incrby key increment
decrby key decrement
incrbyfloat key increment
append key value
strlen key
getset key value
setrange key offset value
getrange key start end
Hash
hset key field value
hsetnx key field value
hget key field
hdel key field [field …]
hlen key
hmget key field [field …]
hmset key field value [filed value …]
hexists key filed
hkeys key
hvals key
hgetall key
hincrby key field
hincrbyfloat key field
hstrlen key field
List
rpush key value [value …]
lpush key value [value …]
linsert key before|after pivot value
lrange key start end
lindex key index
llen key
lpop key
rpop key
lrem key count value
ltrim key start end
lset key index newValue
blpop key [key …] timeout
brpop key [key …] timeout //列表为空且timeout = 0会一直阻塞 列表不为空timeout = 0时,会立刻返回
Set
sadd key element [element …]
srem key element [element …]
scard key
sismember key element
srand key [count] //count 默认为1
spop key
smembers key
sinter key [key …] //集合求交集
suion key [key …] //集合求并集
sdiff key [key …] //集合求差集
sinterstore destination key [key …] //求交集并保存
suionstore destination key [key …] //求并集并保存
sdiffstore destination key [key …] //求差集并保存
ZSet
zadd key score member [score member …]
zcard key
zscore key member
zrank key member //由低到高排名
zrevrank key member //由高到低排名
zrem key member [member …]
zincrby key increment member
zrange key start end [withsocre] //由低到高返回 withscore会返回分数
zrevrange key start end [withscore] //由高到低返回
zrangebyscore key min max [withscore] [limit offset count] //返回指定分数范围内的成员
zrevrangenyscore key max min [withscore] [limit offset count]
zcount key min max //返回指定分数范围内成员个数
zremrangebyrank key start end //删除指定排名内的升序元素
zremrangebyscore key start end //删除指定分数范围内的成员
zinterstore destination numkeys key [key ..] [weights weight [weight …]] [aggregate sum|min|max] //交集运算:destination 计算结果保存到这个键; numkeys 做交集运算的键的数目; weight 做交集运算时每个member的score的权重, 默认为1; sum|min|max 计算成员交集后做汇总,默认是sum
zuionstore destination numkeys key [key ..] [weights weight [weight …]] [aggregate sum|min|max] //并集运算