set 保存一個(gè)鍵值對(duì)
get 通過指定鍵,獲得對(duì)應(yīng)的值
mset 一次性保存多個(gè)鍵值對(duì)
mget 一次性指定多個(gè)鍵,獲得多個(gè)鍵對(duì)應(yīng)的值
getset 指定鍵洞就,獲得該鍵對(duì)應(yīng)原來的值,重新設(shè)置一個(gè)新的值
append 給指定鍵,對(duì)應(yīng)的值腺劣,追加一個(gè)字符串
getrange 獲得指定鍵,對(duì)應(yīng)的字符串的子字符串
incrby 給指定的鍵對(duì)應(yīng)的值因块,添加一個(gè)增量
strlen 通過字符串長度(統(tǒng)計(jì)字節(jié)的長度)
set get 使用
mset mget 使用
192.168.184.130:9379> mset {t}name "wangjun" {t}age 19
OK
192.168.184.130:9379> keys *
1) "{t}name"
2) "{t}age"
3) "345"
4) "wangfei"
5) "mykey"
192.168.184.130:9379> {t}name
(error) ERR unknown command `{t}name`, with args beginning with:
192.168.184.130:9379> get {t}name
"wangjun"
192.168.184.130:9379> mget {t}name {t}age
1) "wangjun"
2) "19"
192.168.184.130:9379> mset aa 'aa' bb 'bb'
(error) CROSSSLOT Keys in request don't hash to the same slot
Redis getrange 命令用于設(shè)置指定 key 的值截取
192.168.184.130:9379> GETRANGE mykey 0 3
"this"
192.168.184.130:9379> GETRANGE mykey 0 -1
"this is my test key"
192.168.184.130:9379>
Redis Getset 命令用于設(shè)置指定 key 的值橘原,并返回 key 的舊值。
192.168.184.130:9379> set db mongodb
-> Redirected to slot [2826] located at 192.168.184.130:9179
OK
192.168.184.130:9179> get db
"mongodb"
192.168.184.130:9179> getset db redis
"mongodb"
192.168.184.130:9179> get db
"redis"
192.168.184.130:9179>
Redis Incr 命令將 key 中儲(chǔ)存的數(shù)字值增一
192.168.184.130:9179> set page_view 20
-> Redirected to slot [15749] located at 192.168.184.130:9379
OK
192.168.184.130:9379> INCR page_view
(integer) 21
192.168.184.130:9379> get page_view
"21"
192.168.184.130:9379> INCR page_view
(integer) 22
192.168.184.130:9379>
Redis Strlen 命令用于獲取指定 key 所儲(chǔ)存的字符串值的長度。當(dāng) key 儲(chǔ)存的不是字符串值時(shí)趾断,返回一個(gè)錯(cuò)誤
192.168.184.130:9379> set mylen 'hello world'
-> Redirected to slot [7705] located at 192.168.184.130:7379
OK
192.168.184.130:7379> get mylen
"hello world"
192.168.184.130:7379> strlen mylen
(integer) 11
Redis Append 命令用于為指定的 key 追加值拒名。
如果 key 已經(jīng)存在并且是一個(gè)字符串, APPEND 命令將 value 追加到 key 原來的值的末尾芋酌。
如果 key 不存在增显, APPEND 就簡單地將給定 key 設(shè)為 value ,就像執(zhí)行 SET key value 一樣脐帝。
192.168.184.130:7379> EXISTS myphone
-> Redirected to slot [13957] located at 192.168.184.130:9379
(integer) 0
192.168.184.130:9379> APPEND myphone 'iphonex'
(integer) 7
192.168.184.130:9379> get myphone
"iphonex"
192.168.184.130:9379> APPEND myphone 'nokia'
(integer) 12
192.168.184.130:9379> get myphone
"iphonexnokia"
192.168.184.130:9379>