[Redis Chapter 7] Set

Source: Internet
Author: User
Tags set set

A set type is an unordered collection that performs operations such as adding, deleting, or judging the existence of an element in that type. Because the internal redis is implemented using a hash table with a null value, the operation has a time complexity of O (1) and a maximum of 2^32-1 strings stored.


Duplicate elements are not allowed in the set set, and another advantage of the set type in function is that it can be set, intersect, and set in difference compared to the list type.


Sadd

129.223.248.154:6379> Sadd Students Tim
(integer) 1
129.223.248.154:6379> Sadd students Tim Ben
(integer) 1


Srem

129.223.248.154:6379> Srem Student Tim
(integer) 0
129.223.248.154:6379> Srem Students Tim
(integer) 1


Smembers, Sismember

129.223.248.154:6379> smembers Students
1) "Ben"
129.223.248.154:6379> Sismember students Ben
(integer) 1
129.223.248.154:6379> Sismember Students Tim
(integer) 0


Sdiff difference Set

129.223.248.154:6379> sadd Setdiffa 1 2 3
(integer) 3
129.223.248.154:6379> Sadd SETDIFFB 2 3 4
(integer) 3
129.223.248.154:6379> sdiff Setdiffa SETDIFFB
1) "1"


Sinter intersection

129.223.248.154:6379> sadd Setintera 1 2 3
(integer) 3
129.223.248.154:6379> Sadd Setinterb 2 3 4
(integer) 3
129.223.248.154:6379> sinter setintera setinterb
1) "2"
2) "3"


Sunion and set

129.223.248.154:6379> sadd Setuniona 1 2 3
(integer) 3
129.223.248.154:6379> Sadd setunionb 2 4 6
(integer) 3
129.223.248.154:6379> sunion Setuniona setunionb
1) "1"
2) "2"
3) "3"
4) "4"
5) "6"


SCard Total number of collections

129.223.248.154:6379> SCard Students
(integer) 1
129.223.248.154:6379> smembers Students
1) "Ben"
129.223.248.154:6379> Srandmember Students
"Ben."
129.223.248.154:6379> Sadd Students Mike
(integer) 1
129.223.248.154:6379> Srandmember Students
"Ben."
129.223.248.154:6379> Srandmember Students
"Mike."
129.223.248.154:6379> Srandmember Students
"Mike."
129.223.248.154:6379> Sadd Memebrs a b C
(integer) 3
129.223.248.154:6379> Srandmember Students 2
1) "Ben"
2) "Mike"


Srandmember

129.223.248.154:6379> Sadd letters a b C
(integer) 3
129.223.248.154:6379> srandmember Letters 2
1) "B"
2) "C"


Spop

129.223.248.154:6379> Spop Letters
"B"
129.223.248.154:6379> smembers Letters
1) "A"
2) "C"
129.223.248.154:6379>

This article is from the "Software Design and Development" blog, please be sure to keep this source http://yuanzhitang.blog.51cto.com/2769219/1789613

[Redis Chapter 7] Set

Related Article

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.