开发者

How to determine if something is a member of an ordered set?

开发者 https://www.devze.com 2023-03-08 00:16 出处:网络
开发者_开发技巧From what I see there\'s no command for this, but I need something similar to the SISMEMBER command, but for ordered sets. Given that there\'s no command for this, what\'s the best way

开发者_开发技巧From what I see there's no command for this, but I need something similar to the SISMEMBER command, but for ordered sets. Given that there's no command for this, what's the best way to determine if something is a member of an ordered set ? Maybe ask for the score of the member with ZCORE and if there's no score than there's no member ?


As you suggested, I would just use ZSCORE. If nil is returned, then the requested member is not in the set. ZRANK would also work, but it's O(log n) and ZSCORE is O(1).

redis> zadd orderedset 1 key1
(integer) 1
redis> zadd orderedset 2 key2
(integer) 1
redis> zscore orderedset key1
"1"
redis> zscore orderedset badkey
(nil)
0

精彩评论

暂无评论...
验证码 换一张
取 消