SINTERSTORE

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Store the intersection in a new set

Usage is sinterstore destination_key source_key1 source_key2.
The behavior is the same as SINTER. The extra part is storing the result set in the specified destination_key.
myset1 = { A, B, C }
myset2 = { B, C, D }
SINTERSTORE dest_key myset1 myset2 = { B, C }

Example

Command>sadd myset1 A B C
Result>3
Command>sadd myset2 B C D
Result>3
Command>sinterstore dest_key myset1 myset2
Result>2
Command>smembers dest_key
Result> 1) B
2) C

View animation



Store the intersection of three sets

Usage is sinterstore destination_key source_key1 source_key2 source_key3.
myset1 = { A, B, C }
myset2 = { B, C, D }
myset3 = { C, E, F }
SUNIONSTORE dest_key myset1 myset2 myset3 = { C }

There is no limit on the number of source keys.
If the destination key already exists, the previous contents are overwritten with the new set.

Example

Command>sadd myset3 C E F
Result>3
Command>sunionstore dest_key myset1 myset2 myset3
Result>1
Command>smembers dest_key
Result> 1) C


A source key can be specified as the destination key

SUNIONSTORE myset1 myset1 myset2 myset3
The previous contents of myset1 are overwritten, and the result is stored in myset1.

Example

Command>sunionstore myset1 myset1 myset2 myset3
Result>1
Command>smembers myset1
Result> 1) C


Syntax

SINTERSTORE destination_key source_key [source_key ...]

  • Available since version 1.0.0.
  • Time complexity is O(N*M). N is the number of members in the smallest set,
    and M is the number of sets.
Related commands SINTERSTORE, SDIFFSTORE
Clients for Java Jedis, Lettuce, Redisson
Clients for C Hiredis

<< SUNIONSTORE SINTERSTORE SDIFFSTORE >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.