本文共 1121 字,大约阅读时间需要 3 分钟。
Sets have 2 main differences with lists:
集与列表有2个主要区别:
Create a set using
使用创建一个集
SADD <setkey> <value>
SADD <setkey> <value>
The same command is used to add more items to the set.
使用相同的命令将更多项目添加到集合中。
Example:
例:
SADD names "Flavio"SADD names "Roger"SADD names "Tony" "Mark" "Jane"
Get all the items in a set using SMEMBERS <setkey>
:
使用SMEMBERS <setkey>
获取集合中的所有项目:
Find out if a value is in a set with SISMEMBER
:
用SISMEMBER
找出一个值是否在集合中:
SISMEMBER names "Flavio"
To know how many items are in a set, use SCARD
:
要知道一组中有多少项,请使用SCARD
:
SCARD names
Get (without removing) an item from the set, randomly:
从集合中随机获取(不删除)项目:
SRANDMEMBER names
Extract (and remove) an item from the set, casually ordered:
从集合中提取(并删除)一个项目,随意排序:
SPOP names
You can extract multiple items at once:
您可以一次提取多个项目:
SPOP names 2
Remove an item from a set by value:
从值集中删除一个项目:
SREM names "Flavio"
Get the items contained in 2 different sets, exclusing elements only included in one with SINTER
:
获取包含在2套不同的项目,exclusing仅包含在一个与元素SINTER
:
SINTER set1 set2
See all the sets commands .
查看所有set命令。
翻译自:
转载地址:http://wxmgb.baihongyu.com/