Redis - 設定 Sinterstore 命令



Redis SINTERSTORE 命令在所有指定集合相交後,將元素儲存在一個集合中。不存在的鍵被視為空集合。如果有一個鍵為空集合,則結果集合也是空的(因為集合與空集合的交集總是導致一個空集合)。

返回值

整數回覆,表示結果集合中的元素數量。

語法

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

redis 127.0.0.1:6379> SINTERSTORE DESTINATION_KEY KEY KEY1..KEYN

示例

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