redis常见命令

redis常见命令

key的常用命令

key * : 显示所有key
exists key:判断某个key是否存在
move key db : 剪切当前库的key到目标库
expire key seconds :为给定的key设置过期时间
ttl key: 查看还有多少秒过期, -1表示永不过期,-2表示已过去(已删除)(不存在了)
type key: 查看key的数据类型

String 字符串类型 单key 单value

set/get/del/append key value
strlen key
incr/decr/ key 一定是key对应的value为数字才能进行加减1
incrby/decrby key value 一定是key对应的value为数字才能进行加减value
getrange/setrange key start end
mset/msetnx key value [key value....]
mget key [key....]
getset key value 先get在set
setex(set with expire)/setnx key seconds value

List 列表 单key 多value value可以重复

lpush/rpush key value [value...] 加入值
lrange key start end 获取列表指定范围的值
lpop/rpop key 弹出值
lindex key index 按照索引下标获取key的值
llen key 获取key的value个数
lrem key count value 删除n个value
ltrim key start stop 截取指定范围的值后再赋值给key
rpoplpush source destination
linsert key before|after pivot value

Set 集合 单key 多value value不重复

sadd key member [member...] 向集合中添加值
sismember key member 判断member 是不是key的member
smembers key 获取集合的值
smembers key 获取集合值的个数
srem key member 删除集合中的指定的member
srandmember key [count] 随机取出key的[count]个|值
spop key 随机出栈
smove source destination member
数学集合类:
差集:sdiff key [key...]
交集:sinter key [key...]
并集: sunion key [key...]

Hash 哈希 KV模式不变,单V是一个键值对

hset|hsetnx key field value
hget key field
hmset key field value [field value...]
hmget key field [field...]
hgetAll key
hdel key field [field...]
hlen key
hexists key field
hkeys/hvals key
HINCRBY|HINCRBYFLOAT key field increment

Zset(sorted set) 有序集合

zadd key [NX|XX] [CH] [INCR] score member [score member ...]
ZADD z1 60 v1 70 v2 80 v3 90 v4 100 v5

ZRANGE|zrevrang key start stop [WITHSCORES]
ZRANGE z1 0 -1
ZRANGE z1 0 -1 withscores

ZRANGEBYSCORE|ZREVRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
ZRANGEBYSCORE z1 60 90
ZRANGEBYSCORE z1 (60 90

ZRANK|zrevbank key member 获取member的下标

ZREM key member [member ...]

zcard key

zcount key min max

你可能感兴趣的:(redis常见命令)