Redis常用命令

Posted yangenyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis常用命令相关的知识,希望对你有一定的参考价值。

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常用命令的主要内容,如果未能解决你的问题,请参考以下文章

Redis-数据结构&常用指令:String,Hash,List...等类型

Redis 常用命令 大全

Redis的常用命令和8大数据类型常用操作大全

Redis的常用命令和8大数据类型常用操作大全

Redis -- 数据库常用命令大全

Redis 键和字符串常用命令