1. SINTER key [key ...]

起始版本:1.0.0

时间复杂度:O(N * M), N 为给定集合当中基数最小的集合, M 为给定集合的个数。

返回指定所有的集合的成员的交集.

例如:

key1 = {a,b,c,d}
key2 = {c}
key3 = {a,c,e}
SINTER key1 key2 key3 = {c}

如果key不存在则被认为是一个空的集合,当给定的集合为空的时候,结果也为空.(一个集合为空,结果一直为空).

1.1. 返回值

结果集的元素.

1.2. demo

# 只要有一个key为空或不存在, 结果就为空集合
127.0.0.1:6379> EXISTS myset
(integer) 1
127.0.0.1:6379> EXISTS myset1
(integer) 0
127.0.0.1:6379> EXISTS myset2
(integer) 1
127.0.0.1:6379> SINTER myset myset1 myset2
(empty list or set)

# 交集
127.0.0.1:6379> SMEMBERS myset
1) "d"
2) "b"
3) "c"
4) "a"
127.0.0.1:6379> SMEMBERS myset2
1) "d"
2) "b"
127.0.0.1:6379> SINTER myset myset2
1) "d"
2) "b"


# 只要有一个key不是set类型,返回错误
127.0.0.1:6379> TYPE key1
string
127.0.0.1:6379> SINTER myset key1
(error) WRONGTYPE Operation against a key holding the wrong kind of value

1.3. 参考

Copyright © wychuan.com 2017 all right reserved,powered by Gitbook该文件修订时间: 2017-10-17 02:48:52

results matching ""

    No results matching ""