Redis - Set Sunion 命令



Redis SUNION 命令用於獲取由所有給定集合的並集生成的集合的成員。不存在的鍵被視為空集合。

返回值

陣列回覆,結果集的成員列表。

語法

以下是 Redis SUNION 命令的基本語法。

redis 127.0.0.1:6379> SUNION KEY KEY1..KEYN

例項

redis 127.0.0.1:6379> SADD myset1 "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset1 "world" 
(integer) 1
redis 127.0.0.1:6379> SADD myset1 "bar" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset2 "hello" 
(integer) 1 
redis 127.0.0.1:6379> SADD myset2 "bar" 
(integer) 1 
redis 127.0.0.1:6379> SUNION myset1 myset2 
1) "bar" 
2) "world" 
3) "hello" 
4) "foo" 
redis_sets.htm
廣告