Redis cheat sheet

1018 ワード

basic

set key value
get key
set cnt 100
incr cnt 
incrby cnt 50
mset a 1 b 2 c 3
mget a b c
type key
randomkey  // random get a key
clear     // clear the screen
rename old new
renamex old new   // if new exists, this will fail
dbsize   // total amount of keys

push pop

rpush list A C F G  // left push  return the list length
lpush list B
lrange list 0 -1  // output list[0,-1]
exists list
del list
rpush list A B C
rpop list


hash

hset myhash field1 "Hello" field2 "world"
hget myhash field2

set (s) and ordered set (z)(ordered by the score)

sadd set 1 2 3 4
smembers set
sismember set 5
zadd zset 1 "value1" 2 "value2"
zrange zset 0 -1 withscores


life-cycle

expire key 100 // key will be removed after 10 seconds
set key 100 ex 30  // 30 seconds
ttl key   // find how many time left