码迷,mamicode.com
首页 > 其他好文 > 详细

Redis常用命令

时间:2019-10-02 16:16:37      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:索引   fence   push   目的   nbsp   交集   获得   tran   从零开始   

Redis 常用命令

key相关

查看所有
keys *
移动key
move [key] [db]
为给定的key设置过期时间
expire [key] [seconds]
查看过期时间-1永不过期-2已过期
ttl [key]
查看key的类型
type [key]
?
flushall
flushdb

string相关

set/get/del/append/strlen
set [key] [value]
get [key]
append [key] [value]
strlen [key]
?
incr/decr/incrby/decrby 只有数字才能加减
incr [key]
decr [key]
incrby [key] [num]
decrby [key] [num]
?
获取或者设置字符串的某些位
getrange/setrange
?
getrange [key] [start] [end] 从零开始
setrange [key] [start] [value]
?
setex (set with expire)/setnx(set if not exist)
setex [key] [seconds] [value]
?
mset/mget/msetnx
mset [k1] [v1] [k2] [v2] [k3] [v3]
mget [k1] [k2] [k3]
msetnx [k1] [v1] [k2] [v2] [k3] [k3]

 

list相关

lpush/rpush/lrange
lpush [listname] [value] [value] [value] ....
rpush [listname] [value] [value] [value] ....
lrange [start] [end]
lrange 0 -1 全取出
?
lpop/rpop
lpop [listname]
rpop [listname]
?
按索引下表获得元素
index [listname] [index]
?
llen [listname]
?
删除 n个
lrem [listname] [value] [n]
?
截取范围的值然后复值
ltrim [listname] [start] [end]
?
源列表目的列表出栈压栈
rpoplpush [listname1] [listname2]
?
lset [listname] [index] [value]
?
linsert [lisname] before/after [v1] [v2]

 

set相关

sadd/smembers/sismember
sadd [setname] [v1] [v2] [v3]
smembers [setname] [value]
smembers [setname]
?
set集合中的个数
scard [setname]
?
删除
srem [setname] [value]
?
随机set中出num个数
srandmember [setname] [num]
?
随机出
spop [setname]
?
从1移到2
smove [setname1] [setname] [value]
?
差集
sdiff [setname1] [setname2]
?
交集
sinter [setname1] [setname2]
?
并集
sunion [setname1] [setname2]

hash相关

hset/hget/hmset/hmget/hgetall/hdel
hmset [hashname] [k1] [v1] [k2] [v2]
hmget [hashname] [k1] [k2] [k3]
?
hset [hashname] [k1] [v1]
hget [hashname] [key]
?
hgetall [hashname]
?
hdel [hasname] [key]
?
hlen [hashname] [key]
?
hexists [hashname] [key]
?
hkeys [hashname]
?
hvals [hashname]
?
hsetnx [hashname] [k1] [v1]

 

zset相关

zadd/zrange
zadd [zsetname] [score1] [v1] [score2] [v2] [score3] [v3]
zrange [zsetname] 0 -1 withscores
zrangebyscore [zsetname] [score1] [score2]
zrangebyscore [zsetname] [score1] [score2] limit [start] [end]
zrem [zsetname] [value]
zcard [zsetname]
zcount [zsetname] [scroe1] [score2]
?
获取score
zrank [zsetname] [value]
?
zrevrange [zsetname] [score1] [score2]
zrevrangebysroce [zsetname] [score1] [score2]

 

Redis常用命令

标签:索引   fence   push   目的   nbsp   交集   获得   tran   从零开始   

原文地址:https://www.cnblogs.com/yangenyu/p/11617505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!