Set data common operations

Source: Internet
Author: User

17. Common operation of SET data
127.0.0.1:6379> sadd set1 1 #向集合set1中放入元素
(integer) 1
127.0.0.1:6379> sadd Set1 2
(integer) 1
127.0.0.1:6379> sadd Set1 3
(integer) 1
127.0.0.1:6379> sadd Set1 4
(integer) 1

127.0.0.1:6379> smembers Set1 #查看集合中所有元素

1) "1"

2) "2"
3) "3"

4) "4"


Srem Set1 1//delete element


127.0.0.1:6379> spop set1 #随机取出一个元素, delete
"Szk"

127.0.0.1:6379> sdiff set1 set2 #比较差集, with Set1 as the main comparison

1) "ZBC"
2) "4"

127.0.0.1:6379> sdiffstore set3 set2 set1 #比较差集, depositing results in Set3

(integer) 2
127.0.0.1:6379> smembers set3 #tab自动补全, but is shown in uppercase
1) "2"

2) "Szk"


sinter Set1 Set2 //Seek intersection


sinterstore set3 Set1 set2 //The intersection is deposited in Set3


sunion Set1 Set2 //Request and set


sunionstore set3 Set1 set2 //Save the Assembly to Set3


sismember Set1 AAA//Determine if an element belongs to a collection


srandmember Set1 //random extraction of an element without deleting




Set data common operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.