YouTip LogoYouTip

Redis Sets

# Redis Sets Redis Sets are unordered collections of strings. Set members are unique, meaning no duplicate data can exist within a set. The encoding of a set object can be either `intset` or `hashtable`. Redis implements sets using hash tables, so the time complexity for adding, deleting, and searching operations is O(1). The maximum number of members in a set is 2^32 - 1 (4294967295, i.e., each set can store over 4 billion members). ### Example redis 127.0.0.1:6379> SADD tutorialkey redis (integer) 1 redis 127.0.0.1:6379> SADD tutorialkey mongodb (integer) 1 redis 127.0.0.1:6379> SADD tutorialkey mysql (integer) 1 redis 127.0.0.1:6379> SADD tutorialkey mysql (integer) 0 redis 127.0.0.1:6379> SMEMBERS tutorialkey 1) "mysql"2) "mongodb"3) "redis" In the above example, we used the **SADD** command to insert three elements into a set named **tutorialkey**. * * * ## Redis Set Commands The table below lists Redis set commands: | No. | Command & Description | | --- | --- | | 1 | [SADD key member1 ](#) Add one or more members to a set | | 2 | (#) Get the number of members in a set | | 3 | [SDIFF key1 ](#) Return the difference between the first set and other sets | | 4 | [SDIFFSTORE destination key1 ](#) Return the difference between given sets and store it in destination | | 5 | [SINTER key1 ](#) Return the intersection of given sets | | 6 | [SINTERSTORE destination key1
← Sets SaddLists Rpushx β†’