1,set key value ex秒数/px 毫秒 nx/xx
127.0.0.1:6379> set name z2 px 1000
OK
127.0.0.1:6379> ttl name
(integer) -2
nx:表示key不存在时执行操作
xx:表示key存在时操作
如:
127.0.0.1:6379> flushdb
OK
127.0.0.1:6379> set jiaxiao dfss
OK
127.0.0.1:6379> set jiaxiao gjjx nx
(nil)
127.0.0.1:6379> get jiaxiao
"dfss"
127.0.0.1:6379> set jiaxiao hdjx xx
OK
127.0.0.1:6379> get jiaxiao
"hdjx"
2,get key
获取键值
3,获取多个key
mget key
4,偏移字符value
127.0.0.1:6379> set suixingpay niubi
OK
127.0.0.1:6379> get suixingpay
"niubi"
127.0.0.1:6379> setrange suixingpay 2 ll
(integer) 5
127.0.0.1:6379> get suixingpay
"nilli"
注意:如果偏移>字符长度,该字符自动补0x00
127.0.0.1:6379> setrange suixingpay 6 c
(integer) 7
127.0.0.1:6379> get suixingpay
"nilli\x00c"
5,附加值
127.0.0.1:6379> append suixingpay @
(integer) 8
127.0.0.1:6379> get suixingpay
"nilli\[email protected]"
6,获取字符串中某个值的范围
注意:对于字符串的下标,左数从0开始,右数从-1开始
127.0.0.1:6379> set area beijing
OK
127.0.0.1:6379> getrange area 2 5
"ijin"
127.0.0.1:6379> getrange area 0 -5
"bei"
7,增加或者减少
127.0.0.1:6379> set ages 20
OK
127.0.0.1:6379> get ages
"20"
127.0.0.1:6379> incr age
(integer) 1
127.0.0.1:6379> get ages
"20"
127.0.0.1:6379> incr ages
(integer) 21
127.0.0.1:6379> get ages
"21"
127.0.0.1:6379> decr ages
(integer) 20
127.0.0.1:6379> get ages
"20"
原文地址:https://blog.51cto.com/yangjunfeng/2394196