set
127.0.0.1:6379> set mykey someValue
OK
127.0.0.1:6379> get mykey
"someValue"
127.0.0.1:6379> set mykey newValue nx
(nil)
127.0.0.1:6379> get mykey
"someValue"
127.0.0.1:6379> set mykey newValue xx
OK
127.0.0.1:6379> get mykey
"newValue"
127.0.0.1:6379> set counter 100 nx
OK
127.0.0.1:6379> get counter
"100"
127.0.0.1:6379> incr counter
(integer) 101
127.0.0.1:6379> incr counter
(integer) 102
127.0.0.1:6379> incrby counter 50
(integer) 152
127.0.0.1:6379> mset a 10 b 20 c 30
OK
127.0.0.1:6379> mget a b c
1) "10"
2) "20"
3) "30"
127.0.0.1:6379> set mykey hello
OK
127.0.0.1:6379> exists mykey
(integer) 1
127.0.0.1:6379> del mykey
(integer) 1
127.0.0.1:6379> exists mykey
(integer) 0
127.0.0.1:6379> randomkey
"hackers"
127.0.0.1:6379> set key some-value
OK
127.0.0.1:6379> expire key 10
(integer) 1
127.0.0.1:6379> get key
"some-value"
127.0.0.1:6379> get key
"some-value"
127.0.0.1:6379> get key
"some-value"
127.0.0.1:6379> get key
"some-value"
127.0.0.1:6379> get key
(nil)
127.0.0.1:6379> set key 100 ex 30
OK
127.0.0.1:6379> ttl key
(integer) 27
127.0.0.1:6379> ttl key
(integer) 25
nx: 没有相同key的情况下成功
xx:在有相同key的情况下成功
incr:自增1
incrby:增加指定值
decr: 自减1
decrby:自减指定值
exists: 判断key是否存在
randomkey: 随机获得一个key
expire: 指定key到过期时间
ttl: 查看key的剩余生存时间
flushdb: 清除当前数据库中的所有键
flushall: 清除所有数据库中的所有键
List
127.0.0.1:6379> rpush mylist A
(integer) 1
127.0.0.1:6379> rpush mylist B
(integer) 2
127.0.0.1:6379> lpush mylist first
(integer) 3
127.0.0.1:6379> lrange mylist 0 -1
1) "first"
2) "A"
3) "B"
127.0.0.1:6379> rpush mylist 0 1 2 3 4 "foo bar"
(integer) 9
127.0.0.1:6379> lrange mylist 0 -1
1) "first"
2) "A"
3) "B"
4) "0"
5) "1"
6) "2"
7) "3"
8) "4"
9) "foo bar"
127.0.0.1:6379> rpop mylist
"foo bar"
127.0.0.1:6379> lpop mylist
"first"
127.0.0.1:6379> del mylist
(integer) 1
rpush: 插入到list尾部
lpush: 插入到list头部
Hashes
127.0.0.1:6379> hmset user:1000 uername Tom birthyear 2011 verified 1
OK
127.0.0.1:6379> hget user:1000 uername
"Tom"
127.0.0.1:6379> hget user:1000 birthyear
"2011"
127.0.0.1:6379> HGETALL user:1000
1) "uername"
2) "Tom"
3) "birthyear"
4) "2011"
5) "verified"
6) "1"
无序集合
127.0.0.1:6379> sadd myset 1 2 3
(integer) 3
127.0.0.1:6379> smembers myset
1) "1"
2) "2"
3) "3"
127.0.0.1:6379> smembers myset
1) "1"
2) "2"
3) "3"
127.0.0.1:6379> sismember myset 3
(integer) 1
127.0.0.1:6379> sismember myset 30
(integer) 0
有序集合
127.0.0.1:6379> zadd hackers 10 "A"
(integer) 1
127.0.0.1:6379> zadd hackers 30 "B"
(integer) 1
127.0.0.1:6379> zadd hackers 12 "C"
(integer) 1
127.0.0.1:6379> zrange hackers 0 -1
1) "A"
2) "C"
3) "B"
127.0.0.1:6379> zrevrange hackers 0 -1
1) "B"
2) "C"
3) "A"
127.0.0.1:6379> zrange hackers 0 -1 withscores
1) "A"
2) "10"
3) "C"
4) "12"
5) "B"
6) "30"