zremrangebylex

1. 基本語法

zremrangebylex(key, min:<string>, max:<string>, callback)

與zrangebylex語法相似,有序集合中若成員分數相同,可強制依字典序(lexicographic ordering)排列成員,並刪除字典序介在maxmin之間的成員,回傳被移除的成員數量

2. 範例

(1) 有序集合的成員分數相同時,按照字典序範圍刪除成員

minmax 參數細節請參考zrangebylex語法

client.del('zset:1');

const key1 = 'zset:1'
const members1 = ['A', 'B', 'C', 'a', 'b', 'c'];
const scores1 = [0, 0, 0, 0, 0, 0];

members1.forEach((mem, ind) => {
    client.zadd(key1, scores1[ind], mem);
})

client.zrange(key1, 0, -1 , redis.print);
client.zremrangebylex(key1, '-', '[C',  redis.print);
client.zrange(key1, 0, -1 , redis.print);
Reply: A,B,C,a,b,c
Reply: 3
Reply: a,b,c

Last updated

Was this helpful?