Redis之學習-字符串類型
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
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
"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"
Redis之學習-字符串類型