当前位置:网站首页>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 :

边栏推荐
猜你喜欢

博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相

Flink learning 6: programming model

Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file

Graduation project: design seckill e-commerce system
TCP-三次握手和四次挥手简单理解

leetcode刷题:二叉树05(翻转二叉树)

Emlog用户注册插件 价值80元

leetcode:1314. 矩阵区域和【二维前缀和模板】

A beautiful API document generation tool

How to telecommute more efficiently | community essay solicitation
随机推荐
Senior developers tell you, how to write excellent code?
Redis:有序集合zset类型数据操作命令
leetcode:1314. 矩阵区域和【二维前缀和模板】
leetcode刷题:二叉树09(二叉树的最小深度)
Apple CMS imitation watermelon video atmospheric response video template source code
【愚公系列】2022年7月 Go教学课程 001-Go语言前提简介
B. All Distinct
软件测试是干什么的 发现缺陷错误,提高软件的质量
Dry goods | detailed explanation of webshell Foundation
User defined path and file name of Baidu editor in laravel admin
毕业设计:设计秒杀电商系统
Three years of graduation, half a year of distance | community essay solicitation
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
2020 Bioinformatics | TransformerCPI
UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
Pytest基础自学系列(一)
MIN_RTO 对话
什么是上下文?
Unity draws the trajectory of pinball and billiards
VIM add interval annotation correctly