13、decr
对key的值做的是减减操作,decr一个不存在key,则设置key为-1
redis 127.0.0.1:6379> get age
"26"
redis 127.0.0.1:6379> decr age
(integer) 25
redis 127.0.0.1:6379> get age
"25"
redis 127.0.0.1:6379>
"26"
redis 127.0.0.1:6379> decr age
(integer) 25
redis 127.0.0.1:6379> get age
"25"
redis 127.0.0.1:6379>
14、decrby
同decr,减指定值。
redis 127.0.0.1:6379> get age
"25"
redis 127.0.0.1:6379> decrby age 5
(integer) 20
redis 127.0.0.1:6379> get age
"20"
redis 127.0.0.1:6379>
"25"
redis 127.0.0.1:6379> decrby age 5
(integer) 20
redis 127.0.0.1:6379> get age
"20"
redis 127.0.0.1:6379>
decrby完全是为了可读性,我们完全可以通过incrby一个负值来实现同样效果,反之一样。
redis 127.0.0.1:6379> get age
"20"
redis 127.0.0.1:6379> incrby age -5
(integer) 15
redis 127.0.0.1:6379> get age
"15"
redis 127.0.0.1:6379>
"20"
redis 127.0.0.1:6379> incrby age -5
(integer) 15
redis 127.0.0.1:6379> get age
"15"
redis 127.0.0.1:6379>
15、append
给指定key的字符串值追加value,返回新字符串值的长度。
例如我们向name的值追加一个@126.com字符串,那么可以这样做:
redis 127.0.0.1:6379> append name @126.com
(integer) 15
redis 127.0.0.1:6379> get name
"HongWan@126.com"
redis 127.0.0.1:6379>
(integer) 15
redis 127.0.0.1:6379> get name
"HongWan@126.com"
redis 127.0.0.1:6379>
16、strlen
取指定key的value值的长度。
redis 127.0.0.1:6379> get name
"HongWan_new"
redis 127.0.0.1:6379> strlen name
(integer) 11
redis 127.0.0.1:6379> get age
"15"
redis 127.0.0.1:6379> strlen age
(integer) 2
redis 127.0.0.1:6379>
"HongWan_new"
redis 127.0.0.1:6379> strlen name
(integer) 11
redis 127.0.0.1:6379> get age
"15"
redis 127.0.0.1:6379> strlen age
(integer) 2
redis 127.0.0.1:6379>