当前位置:网站首页>Redis: operation command for collecting set type data
Redis: operation command for collecting set type data
2022-07-04 04:28:00 【dengfengling999】

Collection types (set)
Redis Of Set yes string An unordered collection of types .
The general idea of data operation of collection type is through key Determine set ,key It's a collection id , The element has no subscript , Only the number of directly operated business data and data .



1.sadd
grammar :sadd key member [member…]
function : Put one or more member Elements are added to the collection key among , Existing in a collection member Elements will be ignored , Will not join .
Return value : The number of new elements added to the collection ( Don't include elements that are ignored ).

for example :


2.smembers
grammar :smembers key
function : Get collection key All member elements in , There is no the key Treat as an empty set .
Return value : Returns all elements of the specified set , There is no the key, Return empty set .

for example :
3.sismember
grammar :sismember key member
function : Judge member Is the element a collection key The elements of
Return value :member Is a collection member that returns 1, Other return 0 .

for example :
4.scard
grammar :scard key
function : Get the number of elements in the collection
Return value : Numbers ,key Number of elements of . Other situations return to 0 .

for example :

5.srem
grammar :srem key member [member…]
function : Remove one or more elements from the collection , Elements that do not exist are ignored .
Return value : Numbers , Number of elements successfully removed , Don't include elements that are ignored .

for example :
6.srandmember
grammar :srandmember key[count]
function : Only available key, Randomly returns an element in the set , The element is not deleted , Still in the collection ;
Provides count when ,count Positive numbers , Return contains count A collection of several elements , Set elements do not repeat .count It's a negative number , Return to one count A collection of the lengths of absolute values , Elements in the collection may be repeated multiple times .
Return value : A collection of one or more elements

for example :count Randomly generated

count: Number generated randomly count>0 No repetition count<0 There is repetition

7.spop
grammar :spop key[count]
function : Randomly delete one or... From the set count Elements .
Return value : Deleted elements ,key Nonexistent or empty collection returns nil.

for example :

8.smove
grammar :smove src dest member
function : take member Elements from src The assembly moves to dest aggregate ,member non-existent ,smove Do not perform operation , return 0, If dest There is member, Only from src Delete in member.
Return value : Successfully returns 1 , Other return 0 .

for example :
9.sdiff
grammar :sdiff key key [key…]
function : Returns the difference of the specified set , Compare with the first set , That is, a set composed of elements in the first set but not in any other set .
Return value : Returns a collection of elements in the first set that are not in the next set , If the elements in the first set are all in the subsequent set, an empty set is returned .

for example :

10.sinter
grammar :sinter key key [key…]
function : Returns the intersection of the specified set , That is, the set composed of elements in all specified sets .
Return value : A collection of intersecting elements , If not, an empty collection is returned .

for example : At first 3 Sets have no working elements , And then when set02 Join in e Then there are common elements

11.sunion
grammar :sunion key key [key…]
function : Returns the union of the specified set , That is, a large set composed of all specified set elements , If the element repeats , Then keep one .
Return value : Returns a large collection of all collection elements , If all key It doesn't exist , Return empty set .

for example :

边栏推荐
猜你喜欢
随机推荐
架构训练毕业设计+总结
Unity 绘制弹球和台球的运动轨迹
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
程序员远程办公喜忧参半| 社区征文
Flink学习7:应用程序结构
Three years of graduation, half a year of distance | community essay solicitation
毕业设计项目
Unity Resource path
EventBridge 在 SaaS 企业集成领域的探索与实践
线程常用的方法
96% of the collected traffic is prevented by bubble mart of cloud hosting
RHCSA 04 - 进程管理
(pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
(指针)编写函数void fun(int x,int *pp,int *n)
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
RHCSA 06 - suid, sgid, sticky bit(待补充)
2020 Bioinformatics | TransformerCPI
VIM add interval annotation correctly
RHCSA 08 - automount配置
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线








