命令格式:code
LPUSH key value [value2 value3...]
:推入值LPOP key value
:推出值LLEN key
:獲取list長度LPUSHX key value [value2 value3...]
:只有存在這個key
,才推入值:RPUSH key value [value2 value3...]
:反向推入值RPUSHX key value [value2 value3...]
:只有存在這個key
,才反向推入值
# 推入一個值 127.0.0.1:6379> LPUSH order 1 (integer) 1 # 推入另外一個值 127.0.0.1:6379> LPUSH order 2 (integer) 2 # 彈出一個值 127.0.0.1:6379> LPOP order "2" # 彈出另外一個值 127.0.0.1:6379> LPOP order "1" # list爲空的時候,彈出的爲nil 127.0.0.1:6379> LPOP order (nil) # 推入一個值 127.0.0.1:6379> LPUSH order 2 (integer) 1 # 推入多個值 127.0.0.1:6379> LPUSH order 2 3 4 (integer) 4 # 獲取list長度 127.0.0.1:6379> LLEN order (integer) 4 # 獲取索引爲0-10的值 127.0.0.1:6379> LRANGE order 0 10 1) "10000" 2) "4" 3) "3" 4) "2" 5) "2" # 推入不存在的list,返回0 127.0.0.1:6379> LPUShX goods 1 (integer) 0 # 推如存在的list 127.0.0.1:6379> LPUShX order -1 (integer) 6 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "10000" 3) "4" 4) "3" 5) "2" 6) "2" # 反序推入值 127.0.0.1:6379> RPUSH goods 1 2 3 4 (integer) 4 127.0.0.1:6379> LRANGE goods 0 10 1) "1" 2) "2" 3) "3" 4) "4" # 只有存在才推入值 127.0.0.1:6379> RPUSHX goods2 1 2 (integer) 0
命令格式:索引
LRANGE key start value
:獲取某個區間索引的值
127.0.0.1:6379> LRANGE order 0 10 1) "4" 2) "3" 3) "2" 4) "2" 127.0.0.1:6379> LRANGE order 0 2 1) "4" 2) "3" 3) "2"
命令格式:top
LINDEX key index
127.0.0.1:6379> LINDEX order 0 "10000"
命令格式:co
LINDEX key index value
127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "10000" 3) "3" 127.0.0.1:6379> LSET order 1 1 OK 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "1" 3) "3"
命令格式:block
LINDEX key index BEFORE|AFTER key value
127.0.0.1:6379> LINSERT order BEFORE 10000 -10 (integer) 7 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "-10" 3) "10000" 4) "4" 5) "3" 6) "2" 7) "2" 127.0.0.1:6379> LINSERT order BEFORE s -10 (integer) -1 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "-10" 3) "10000" 4) "4" 5) "3" 6) "2" 7) "2"
命令格式:index
LREM key count value
:根據指定值刪除指定值及其周圍指定數量的值tar- count > 0 : 正序刪除|count|數量的value值 - count < 0 : 倒序刪除|count|數量的value值 - count = 0 : 刪除全部指定的值
127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "-10" 3) "10000" 4) "4" 5) "3" 6) "2" 7) "2" 127.0.0.1:6379> LREM order 2 -10 (integer) 1 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "10000" 3) "4" 4) "3" 5) "2" 6) "2" 127.0.0.1:6379> LREM order -2 4 (integer) 1 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "10000" 3) "3" 4) "2" 5) "2" 127.0.0.1:6379> LREM order 0 2 (integer) 2 127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "10000" 3) "3"
命令格式:
LTRIM key start stop
:將區間內的值刪除
127.0.0.1:6379> LRANGE order 0 10 1) "-1" 2) "1" 3) "3" 127.0.0.1:6379> LTRIM order 1 2 OK 127.0.0.1:6379> LRANGE order 0 10 1) "1" 2) "3"