SINTER key1 key2 ... keyN
Return the members of a set resulting from the intersection of all the sets hold at the specified keys. Like in LRANGE the result is sent to the client as a multi-bulk reply.
TIME COMPLEXITY: O(N*M) worst case where N is the cardinality of the smallest set and M the number of sets
Note:
Non-existing keys are considered like empty sets, so if one of the keys is missing an empty set is returned (since the intersection with an empty set always is an empty set).
RETURN VALUE: Multi bulk reply, specifically the list of common elements.
Syntax:
SINTER key1 key2 ... keyN
Example 1: When the intersection contains some elements.
redis:6379> SADD key1 a b c d(integer) 4redis:6379> SADD key2 d f(integer) 2redis:6379> SADD key3 g h(integer) 2redis:6379> SINTER key1 key21) "d"
Output
d
Example 2: When the intersection does not contain any element.
redis:6379> SADD key1 a b c d(integer) 4redis:6379> SADD key2 d f(integer) 2redis:6379> SADD key3 g h(integer) 2redis:6379> SINTER key1 key2 key3(empty array)
Output
empty array
No comments:
Post a Comment