w3resource

Redis Sets: SINTER

Redis SINTER Command

Redis SINTER command is used to return the members of the set resulting from the intersection of all the specified sets. Keys that do not exist are considered to be empty sets and if one of the keys being an empty set, the resulting set is also empty.

Here are some common uses and scenarios for the "SINTER" command:

  • Common Elements: Identify members that are common across multiple sets.
  • Shared Memberships: Determine shared memberships, such as users in multiple groups or tags shared by multiple resources.
  • Data Analysis: Perform data analysis to find overlapping items in different datasets.
  • Filtering: Filter elements to retain only those present in all specified sets.
  • Interest Grouping: Create groups based on common interests or attributes found in all sets.

Syntax:

SINTER KEY KEY1..KEYN

Available since:

1.0.0.

Return Value:

Array reply, list with members of the resulting set.

Return Value Type:

Array

Example: Redis SINTER of two sets

127.0.0.1:6379> SADD mycolor1 R G B
(integer) 3
127.0.0.1:6379> SADD mycolor2 G B Y
(integer) 3
127.0.0.1:6379> SINTER mycolor1 mycolor2
1) "G"
2) "B"

Example: Redis SINTER of three sets

How is a sinter key1 key2 key3. 
mycolor1 = {R G B} 
mycolor2 = {G B Y} 
mycolor3 = {B W O} 
SINTER mycolor1 mycolor2 mycolor3 = {B} 
The number of key is not limited.

127.0.0.1:6379> SADD mycolor3 B W O
(integer) 3
127.0.0.1:6379> SINTER mycolor1 mycolor2 mycolor3
1) "B"

Previous: Redis Sets SDIFFSTORE
Next: Redis Sets SINTERSTORE



Follow us on Facebook and Twitter for latest update.