Redis - 設定 Sunionstore 命令



Redis SUNIONSTORE 命令用於儲存所有給定集合的並集產生的集合中的成員。不存在的鍵被視為空集。

返回值

整數答覆,結果集中的元素數。

語法

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

redis 127.0.0.1:6379> SUNIONSTORE DESTINATION 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> SUNIONSTORE myset myset1 myset2 
(integer) 1 
redis 127.0.0.1:6379> SMEMBERS myset 
1) "bar" 
2) "world" 
3) "hello" 
4) "foo"
redis_sets.htm
廣告
© . All rights reserved.