1、增長spa
一、lpush [lpush key valus...] 相似於壓棧操做,將元素放入頭部code
127.0.0.1:6379> lpush plist ch0 ch1 ch2 (integer) 3 127.0.0.1:6379> lrange plist 0 3 1) "ch2" 2) "ch1" 3) "ch0" 127.0.0.1:6379> lpush plist ch4 (integer) 4 127.0.0.1:6379> lrange plist 0 4 1) "ch4" 2) "ch2" 3) "ch1" 4) "ch0"
2 、lpushx [lpushx key valus]:只能插入已經存在的key,且一次只能插入一次blog
127.0.0.1:6379> lpushx pl ch (integer) 0 127.0.0.1:6379> lpushx plist ch5 ch6 (error) ERR wrong number of arguments for 'lpushx' command 127.0.0.1:6379> lpushx plist ch5 (integer) 5 127.0.0.1:6379> lrange plist 0 5 1) "ch5" 2) "ch4" 3) "ch2" 4) "ch1" 5) "ch0"
三、rpush [rpush key valus...] :將元素push在list的尾部索引
127.0.0.1:6379> rpush plist ch6 (integer) 6 127.0.0.1:6379> lrange plist 0 6 1) "ch5" 2) "ch4" 3) "ch2" 4) "ch1" 5) "ch0" 6) "ch6" 127.0.0.1:6379> rpush plist ch7 ch8 (integer) 8 127.0.0.1:6379> lrange plist 0 8 1) "ch5" 2) "ch4" 3) "ch2" 4) "ch1" 5) "ch0" 6) "ch6" 7) "ch7" 8) "ch8"
四、rpushx [rpushx key valus...] :相對於lpushxrem
五、linsert [linsert key before/after pivot value]:將值插入到pivot的前面或後面。返回列表元素個數。若是參照點pivot不存在不插入。若是有多個pivot,以離表頭最近的爲準class
127.0.0.1:6379> linsert plist before ch1 chi (integer) 9 127.0.0.1:6379> lrange plist 0 9 1) "ch5" 2) "ch4" 3) "ch2" 4) "chi" 5) "ch1" 6) "ch0" 7) "ch6" 8) "ch7" 9) "ch8" 127.0.0.1:6379> linsert plist before chii chi2 (integer) -1 127.0.0.1:6379> linsert plist after chi cha (integer) 10 127.0.0.1:6379> lrange plist 0 10 1) "ch5" 2) "ch4" 3) "ch2" 4) "chi" 5) "cha" 6) "ch1" 7) "ch0" 8) "ch6" 9) "ch7" 10) "ch8"
//以上插入操做均是返回list的長度
2、刪除command
一、lpop 、rpop:分別爲刪除頭部和尾部,返回被刪除的元素im
127.0.0.1:6379> lpop plist "ch5" 127.0.0.1:6379> lrange plist 0 10 1) "ch4" 2) "ch2" 3) "chi" 4) "cha" 5) "ch1" 6) "ch0" 7) "ch6" 8) "ch7" 9) "ch8" 127.0.0.1:6379> rpop plist "ch8" 127.0.0.1:6379> lrange plist 0 10 1) "ch4" 2) "ch2" 3) "chi" 4) "cha" 5) "ch1" 6) "ch0" 7) "ch6" 8) "ch7"
2 、ltrim [ltrim key range_l range_r]:保留區域類的元素,其餘的刪除error
127.0.0.1:6379> ltrim plist 0 3 OK 127.0.0.1:6379> lrange plist 0 10 1) "ch4" 2) "ch2" 3) "chi" 4) "cha"
三、lrem [lrem key count value] :移除等於value的元素,當count>0時,從表頭開始查找,移除count個;當count=0時,從表頭開始查找,移除全部等於value的;當count<0時,從表尾開始查找,移除|count| 個。查詢
cout >0
127.0.0.1:6379> lrange plist 0 10 1) "ch0" 2) "ch0" 3) "ch0" 4) "ch4" 5) "chi" 6) "cha" 7) "ch0" 8) "ch0" 9) "ch0" 10) "ch0" 127.0.0.1:6379> lrem plist 5 ch0 (integer) 5 127.0.0.1:6379> lrange plist 0 10 1) "ch4" 2) "chi" 3) "cha" 4) "ch0" 5) "ch0"
count <0
127.0.0.1:6379> lrange plist 0 10 1) "ch0" 2) "ch9" 3) "ch0" 4) "ch0" 5) "ch0" 6) "ch4" 7) "chi" 8) "cha" 9) "ch0" 10) "ch0" 127.0.0.1:6379> lrem plist -5 ch0 (integer) 5 127.0.0.1:6379> lrange plist 0 10 1) "ch0" 2) "ch9" 3) "ch4" 4) "chi" 5) "cha"
3、修改
lset [lset key index value] : 設置列表指定索引的值,若是指定索引不存在則報錯
127.0.0.1:6379> lset plist 0 ch2 OK 127.0.0.1:6379> lrange plist 0 10 1) "ch2" 2) "ch9" 3) "ch4" 4) "chi" 5) "cha"
4、查詢
一、lindex [lindex key index]:經過索引index獲取列表的元素、key>=0從頭至尾,key<0從尾到頭
127.0.0.1:6379> lrange plist 0 10 1) "ch2" 2) "ch9" 3) "ch4" 4) "chi" 5) "cha" 127.0.0.1:6379> lindex plist 0 "ch2" 127.0.0.1:6379> lindex plist -0 "ch2" 127.0.0.1:6379> lindex plist -1 "cha" 127.0.0.1:6379> lindex plist 5 (nil)
二、lrange [lrange key range_l range_r]:0 表頭、-1表尾