redis列表
A list is a set of key-values pairs linked to each other.
列表是一组相互链接的键值对。
LPUSH
and RPUSH
are the two commands to work with lists.
LPUSH
和RPUSH
是使用列表的两个命令。
You use the command LPUSH <listkey> <value>
to create the first item.
您使用命令LPUSH <listkey> <value>
创建第一项。
Example:
例:
LPUSH names "Flavio"
Then subsequent items can be added at the bottom of the list: RPUSH <listkey> <value>
然后可以将后续项添加到列表的底部: RPUSH <listkey> <value>
Or at the top of the list with LPUSH <listkey> <value>
.
或在列表顶部使用LPUSH <listkey> <value>
。
Example:
例:
LPUSH names "Flavio"
LPUSH names "Syd"
RPUSH names "Roger"
You can add duplicate values into a list.
您可以将重复的值添加到列表中。
LPUSH names "Flavio"
LPUSH names "Flavio"
RPUSH names "Flavio"
A list can hold a big number of items, more than 4 billions.
列表可以容纳大量项目,超过40亿个。
Count how many items are in a list with LLEN <listkey>
.
使用LLEN <listkey>
列表中有多少项。
Get and remove the last item in a list with RPOP <listkey>
. Do the same with the first item with LPOP
.
使用RPOP <listkey>
获取和删除列表中的最后一项。 使用LPOP
对第一个项目执行相同的LPOP
。
Remove multiple items from the list using the LREM
command.
使用LREM
命令从列表中删除多个项目。
You can limit how long a list is using LTRIM
.
您可以限制列表使用LTRIM
。
LTRIM names 0 1
cuts the list to just 2 items, item at position 0 (the first) and item at position 1.
LTRIM names 0 1
将列表切为2个项目,位于位置0(第一个)的项目和位于位置1的项目。
Using LRANGE
you can get the items in the list.
使用LRANGE
您可以获得列表中的项目。
LRANGE names 0 100
returns items starting at position 0 (the beginning), ending at position 100.
LRANGE names 0 100
返回从位置0(开始)开始,到位置100结束的项目。
LRANGE names 0 0
returns the item in position 0 (the first).
LRANGE names 0 0
返回位置0(第一个)的项目。
LRANGE names 2 2
returns the item in position 2.
LRANGE names 2 2
返回位置2的项目。
LRANGE names 0 -1
lists all items.
LRANGE names 0 -1
列出所有项目。
See all the lists commands here.
在此处查看所有列表命令。
redis列表