How to get DIFF on sorted set

后端 未结 1 926
误落风尘
误落风尘 2021-01-02 14:52

How do I get most weighted elements from a sorted set, but excluding those found in another set(or list or hash).

>zadd all 1 one
>zadd all 2 two
>         


        
相关标签:
1条回答
  • 2021-01-02 15:20

    Note: I assume you've meant sadd disabled two

    As you've found out, SDIFF does not operate on sorted sets - that is because defining the difference between sorted sets isn't trivial.

    What you could do is first create a temporary set with ZUNIONSTORE and set the intersect's scores to 0. Then do a range excluding the 0, e.g.:

    127.0.0.1:6379> ZADD all 1 one 2 two 3 three
    (integer) 3
    127.0.0.1:6379> SADD disabled two
    (integer) 1
    127.0.0.1:6379> ZUNIONSTORE tmp 2 all disabled WEIGHTS 1 0 AGGREGATE MIN
    (integer) 3
    127.0.0.1:6379> ZREVRANGEBYSCORE tmp +inf 1 WITHSCORES
    1) "three"
    2) "3"
    3) "one"
    4) "1"
    
    0 讨论(0)
提交回复
热议问题