Is there a feature to maintain the cardinality of the sorted sets in redis a constant? -


Example, I need a key (sorted set) to store only 200 elements if a new element in the set (Always with highscore), one element with the lowest score in the set should be automatically removed; the cardinality of the set set should be maintained continuously.

No, there is no such facility, but this is very easy to achieve.

First of all, remember that members are unique, so there can be a situation (unless this is the case in case of your use) where adding new members with new (high) scores actually If the current score will be updated, then, after each of your ZADD , do this:

  c = redis.zcard ('key')  

if the response to jdcard is <200>, the difference to trim the set sorted by rank Use:

  if c & gt; 200: r.zremrangebyrank ('key', 0, c-200 -1)  

(BTW, if you are only adding one member, always from top one [lowest Rated member]


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -