Redis四 Redis資料型別

2021-09-02 08:54:48 字數 1589 閱讀 6223

redis是乙個高效能的資料結構伺服器,稱之為資料結構伺服器的原因是,它提供了豐富的資料型別以滿足不同的應用場景,本文對redis的資料型別以及對這些型別可能的操作進行總結。

redis常用的資料型別包括string、set、list、hash以及sorted set.redis本身是k/v系統,這裡的資料型別指的是value的型別,而不是key的型別,key的型別只有一種即string,redis要求key這個字串的長度必須大於1。

redis提供了type命令用於判斷key對應的value的型別,例如 type key,返回值有如下幾種,

none,string,hash,set,sortedset,list,其中none表示value是nil。

string提供了如下操作:

localhost:6381> set key1 10

oklocalhost:6381> set key2 abc

oklocalhost:6381> set key3 this is a book

(error) err syntax error

localhost:6381> set key3 "this is a book"

oklocalhost:6381> get key1

"10"

localhost:6381> ket ke2

(error) err unknown command 'ket'

localhost:6381> get key3

"this is a book"

localhost:6381> get key2

"abc"

localhost:6381>

localhost:6381> incr count

(integer) 1

localhost:6381> set key1 abc

oklocalhost:6381> incr key1

(error) err value is not an integer or out of range

localhost:6381> incrby key4 10

(integer) 10

localhost:6381> incrby key4 100

(integer) 110

localhost:6381> incrby key4 -100

(integer) 10

localhost:6381> incrby key4 -200

(integer) -190

localhost:6381>

localhost:6381> getset abc 1

"2"localhost:6381> getset key5 1

(nil)

localhost:6381> get key5

"1"localhost:6381> getset key5 2

"1"localhost:6381> get key5

"2"localhost:6381>

Redis學習筆記之四 redis資料型別

redis資料型別 redis支援五種型別的資料 string 字串 hash 雜湊 list 列表 set 集合 zset 有序集合 sorted set 1.string 字串 string是redis最基本的型別,可以理解成與memcached一模一樣的型別,乙個key對應乙個value。st...

redis資料型別

redis對比與memcached 最大的優勢就是支援更多靈活的資料結構,豐富的資料操作 redis現支援的資料型別有 字串,列表,集合,雜湊,有序集合 1.字串 普通資料型別 2.列表 簡單的字串列表,按照插入順序排序。你可以新增乙個元素到列表的頭部 左邊 或者尾部 右邊 適用於 對資料頭尾操作頻...

Redis 資料型別

redis支援五種資料型別 string 字串 hash 雜湊 list 列表 set 集合 及zset sorted set 有序集合 string是redis最基本的型別,你可以理解成與memcached一模一樣的型別,乙個key對應乙個value。string型別是二進位制安全的。意思是red...