Redis(2.8.3) 命令學習 - Lists

來源:互聯網
上載者:User

標籤:

BLPOP key [key ...] timeout

Remove and get the first element in a list, or block until one is available 

More: http://redis.io/commands/blpop, http://www.redis.cn/commands/blpop.html

 

BRPOP key [key ...] timeout

Remove and get the last element in a list, or block until one is available

More: http://redis.io/commands/brpop, http://www.redis.cn/commands/brpop.html

 

BRPOPLPUSH source destination timeout

Pop a value from a list, push it to another list and return it; or block until one is available

More: http://redis.io/commands/brpoplpush, http://www.redis.cn/commands/brpoplpush.html

 

LINDEX key index

Get an element from a list by its index

127.0.0.1:6379> LPUSH foo 1 3 5 7 9(integer) 5127.0.0.1:6379> LINDEX foo 1"7"127.0.0.1:6379> LINDEX foo -2"3"

 

LINSERT key BEFORE|AFTER pivot value

Insert an element before or after another element in a list

127.0.0.1:6379> LPUSH foo 10 20 40 80(integer) 4127.0.0.1:6379> LINSERT foo BEFORE 20 80(integer) 5127.0.0.1:6379> LRANGE foo 0 -11) "80"2) "40"3) "80"4) "20"5) "10"127.0.0.1:6379> LINSERT foo AFTER 80 0(integer) 6127.0.0.1:6379> LRANGE foo 0 -11) "80"2) "0"3) "40"4) "80"5) "20"6) "10"

More: http://redis.io/commands/linsert, http://www.redis.cn/commands/linsert.html

 

LLEN key

Get the length of a list

127.0.0.1:6379> LPUSH foo 1 2 4(integer) 3127.0.0.1:6379> LLEN foo(integer) 3

 

LPOP key

Remove and get the first element in a list

127.0.0.1:6379> LPUSH foo 1 2 4 8(integer) 4127.0.0.1:6379> LPOP foo"8"127.0.0.1:6379> LPOP foo"4"

 

LPUSH key value [value ...]

Prepend one or multiple values to a list

127.0.0.1:6379> LPUSH foo 1(integer) 1127.0.0.1:6379> LPUSH foo 2 4(integer) 3127.0.0.1:6379> LRANGE foo -1 0(empty list or set)127.0.0.1:6379> 127.0.0.1:6379> LRANGE foo 0 -11) "4"2) "2"3) "1"

 

LPUSHX key value

Prepend a value to a list, only if the list exists

127.0.0.1:6379> LPUSHX foo 1(integer) 0127.0.0.1:6379> LRANGE foo 0 -1(empty list or set)127.0.0.1:6379> LPUSH foo 1(integer) 1127.0.0.1:6379> LPUSHX foo 2(integer) 2127.0.0.1:6379> LRANGE foo 0 -11) "2"2) "1"

 

LRANGE key start stop

Get a range of elements from a list

127.0.0.1:6379> LPUSH foo 1 3 5 7 9(integer) 5127.0.0.1:6379> LRANGE foo 1 31) "7"2) "5"3) "3"127.0.0.1:6379> LRANGE foo 0 -11) "9"2) "7"3) "5"4) "3"5) "1"

 

LREM key count value

Remove elements from a list

127.0.0.1:6379> RPUSH foo 1 2 1 3 1 4(integer) 6127.0.0.1:6379> LREM foo 2 1(integer) 2127.0.0.1:6379> LRANGE foo 0 -11) "2"2) "3"3) "1"4) "4"127.0.0.1:6379> RPUSH foo 3 1 3 2 1 3(integer) 10127.0.0.1:6379> LREM foo -3 3(integer) 3127.0.0.1:6379> LRANGE foo 0 -11) "2"2) "3"3) "1"4) "4"5) "1"6) "2"7) "1"127.0.0.1:6379> LREM foo 0 1(integer) 3127.0.0.1:6379> LRANGE foo 0 -11) "2"2) "3"3) "4"4) "2"

More: http://redis.io/commands/lrem, http://www.redis.cn/commands/lrem.html

 

LSET key index value

Set the value of an element in a list by its index

127.0.0.1:6379> RPUSH foo 1 2 3 4 5(integer) 5127.0.0.1:6379> LSET foo 3 0OK127.0.0.1:6379> LRANGE foo 0 -11) "1"2) "2"3) "3"4) "0"5) "5"


LTRIM key start stop

Trim a list to the specified range

127.0.0.1:6379> RPUSH foo 1 3 5 7 9(integer) 5127.0.0.1:6379> LTRIM foo 3 -1 OK127.0.0.1:6379> LRANGE foo 0 -11) "7"2) "9"

More: http://redis.io/commands/ltrim, http://www.redis.cn/commands/ltrim.html

 

RPOP key

Remove and get the last element in a list

127.0.0.1:6379> RPUSH foo 1 2 3 4(integer) 4127.0.0.1:6379> RPOP foo"4"127.0.0.1:6379> RPOP foo"3"127.0.0.1:6379> LRANGE foo 0 -11) "1"2) "2"

 

RPOPLPUSH source destination

Remove the last element in a list, prepend it to another list and return it

127.0.0.1:6379> RPUSH foo 1 3 5(integer) 3127.0.0.1:6379> RPUSH bar 2 4(integer) 2127.0.0.1:6379> RPOPLPUSH foo bar"5"127.0.0.1:6379> LRANGE foo 0 -11) "1"2) "3"127.0.0.1:6379> LRANGE bar 0 -11) "5"2) "2"3) "4"127.0.0.1:6379> RPOPLPUSH bar bar"4"127.0.0.1:6379> LRANGE bar 0 -11) "4"2) "5"3) "2"

More: http://redis.io/commands/rpoplpush, http://www.redis.cn/commands/rpoplpush.html

 

RPUSH key value [value ...]

Append one or multiple values to a list

127.0.0.1:6379> RPUSH foo 1(integer) 1127.0.0.1:6379> RPUSH foo 1 2 3(integer) 4127.0.0.1:6379> LRANGE foo 0 -11) "1"2) "1"3) "2"4) "3"

 

RPUSHX key value

Append a value to a list, only if the list exists

127.0.0.1:6379> RPUSHX foo 1(integer) 0127.0.0.1:6379> LRANGE foo 0 -1(empty list or set)127.0.0.1:6379> RPUSH foo 1(integer) 1127.0.0.1:6379> RPUSHX foo 2(integer) 2127.0.0.1:6379> LRANGE foo 0 -11) "1"2) "2"

 

Redis(2.8.3) 命令學習 - Lists

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.