srem

1. 基本語法

srem(key, value[, value, ...], callback)

value存在於集合成員中,將value從集合中移除,若value不存在則忽略,執行結束後回傳被移除的成員數量;若key不存在則回傳0。

2. 範例

(1) 內容

const arr = ['apple', 'potato', 'onion']
client.sadd('food', arr);
client.smembers('food', redis.print);

client.srem('food', 'potato', redis.print);
client.smembers('food', redis.print);
Reply: apple,onion,potato
Reply: 1
Reply: apple,onion

(2) 透過Array來決定移除成員

srem(key, [value, ...], callback)

const arr = ['apple', 'potato', 'onion', 'tomato', 'melon']
client.sadd('food', arr);
client.smembers('food', redis.print);

const rem = ['potato', 'tomato', 'watermelon'];
client.srem('food', rem, redis.print);
client.smembers('food', redis.print);
Reply: tomato,apple,onion,potato,melon
Reply: 2
Reply: onion,melon,apple

Last updated

Was this helpful?