1.赋值
set key value
如果key已存在,则value被新值覆盖
localhost:6379> set name yanlei
OK
2.取值
get key value
localhost:6379> get name
"yanlei"
3.递增数值
incr key (key的value必须为数字)
localhost:6379> get name
"yanlei"
localhost:6379> set index 1
OK
localhost:6379> get index
"1"
localhost:6379> incr index
(integer) 2
localhost:6379> incr index
(integer) 3
localhost:6379> get index
"3"
localhost:6379> set name yanlei
OK
localhost:6379> incr name
(error) ERR value is not an integer or out of range//非数字报错
4.增加指定整数
incrby key num
localhost:6379> set index 1
OK
localhost:6379> incrby index 5
(integer) 6
5.递减数值
decr key
localhost:6379> set index 10
OK
localhost:6379> decr index
(integer) 9
6.减少指定整数
decrby key num
localhost:6379> set index 10
OK
localhost:6379> decrby index 6
(integer) 4
7.增加指定的浮点数
incrbyfloat key floatvalue
127.0.0.1:6379> set price 7.7
OK
127.0.0.1:6379> incrbyfloat price 1.1
"8.8"
8.向尾部增加字符串
append key value
localhost:6379> set city shengyang
OK
localhost:6379> append city ' of china'
(integer) 18
localhost:6379> get city
"shengyang of china"
9.获取字符串长度
strlen key
localhost:6379> set money 123456
OK
localhost:6379> strlen money
(integer) 6
10.设置(获取)多个键 值
mset key1 value1 key2 value2 ....
mget key1 key2 ...
localhost:6379> mset brand focus color block price 120000
OK
localhost:6379> mget brand color price
1) "focus"
2) "block"
3) "120000"