下面是字符串類型的相關命令node
賦值採用如下命令git
SET key hello
若是客戶端返回爲OK
則證實寫入成功github
取值採用如下命令redis
GET key // 返回 "hello" GET key2 // 返回 (nil)
若是key值存在,則返回存儲的鍵值hello
code
若是key不存在,redis會返回nil
對象
INCR num
當要操做的鍵不存在時默認鍵值爲0,因此運行該指令後結果爲1,當鍵值不爲整數時,redis會提示錯誤字符串
INCR key // 會返回如下錯誤 (error) ERR value is not an integer or out of range
注意:
建議使用incr
進行自增,而不是使用set
來執行+1
操做,由於incr
操做是原子性的。若是同時有兩個客戶端操做,最終值只會+1
,
INCRBY num 10
返回num增長10後的值
若是增長鍵的值爲字符串,則報錯以下:(error) ERR value is not an integer or out of range
get
DECR num DECRBY num 10
DECR
命令遞減1string
DECRBY
命令遞減指定數值it
若是鍵的值爲字符串,則報錯以下:(error) ERR value is not an integer or out of range
INCRBYFLOAT num 1.1
以上命令爲鍵爲num的值增長1.1
若是鍵的值爲字符串,則報錯以下:(error) ERR value is not an integer or out of range
APPEND key " world!"
返回值爲字符串的總長度,此時key的值爲hello world!
STRLEN key
MGET key key2 key3 MSET key value1 key2 value2 key3 value3
鍵的命名通常格式爲
對象類型:對象id:對象屬性
若是多個單次則使用.分開
如:存儲id爲1的好友列表,命名以下:user:1:friends
關於字符串的node示例,請跳轉至github查看
https://github.com/Crazycheng...