Latest web development tutorials

Redis Sunionstore 命令

Redis集合(Set)

Redis Sunionstore 命令將給定集合的並集存儲在指定的集合destination 中。 如果destination 已經存在,則將其覆蓋。

語法

redis Sunionstore 命令基本語法如下:

redis 127.0.0.1:6379> SUNIONSTORE DESTINATION KEY KEY1..KEYN

可用版本

>= 1.0.0

返回值

結果集中的元素數量。

實例

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集合(Set)