Javatpoint Logo
Javatpoint Logo

Redis Sets

Redis Sets are an unordered collection of unique strings. Unique strings means there is not a single string repeated in the set.

In Redis set add, remove, and test for the existence of members in O(1) (constant time regardless of the number of elements contained inside the Set). The maximum length of a list is more than 4 billion of elements per set.

EXAMPLE

Redis Sets 1

In the above example, you can see that we have added 4 elements in the set by using SADD command. But only 3 elements are retrieved by using SMEMBERS command because one element was duplticate and Redis sets read duplicate values only once.


Redis Sets Commands

Index Command Description
1 SADD key member1 [member2] It is used to add one or more members to a set.
2 SCARD key It is used to getsthe number of members in a set.
3 SDIFF key1 [key2] It is used to subtract multiple sets.
4 SDIFFstore destination key1 [key2] It is used to subtract multiple sets and stores the resulting set in a key.
5 SINTER key1 [key2] It is used to intersect multiple sets.
6 SINTERSTORE destination key1 [key2] It is used to intersect multiple sets and stores the resulting set in a key.
7 SISMEMBER key member It is used to determine if a given value is a member of a set.
8 SMOVE source destination member It is used to move a member from one set to another.
9 SPOP key It is used to remove and returns a random member from a set.
10 SRANDMEMBER key [count] It is used to get one or multiple random members from a set.
11 SREM key member1 [member2] It is used to remove one or more members from a set.
12 SUNION key1 [key2] It is used to add multiple sets.
13 SUNIONSTORE destination key1 [key2] It is used to add multiple sets and stores the resulting set in a key.
14 SSCAN key cursor [match pattern] [count count] It is used to incrementally iterates set elements.

Next TopicRedis Sorted Sets





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA