-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Description
Summary
As of Redis 3.2, ZADD provides two options for adding key/score pairs to a sorted set:
XX: Only update elements that already exist. Never add elements.
NX: Don't update already existing elements. Always add new elements.
I would like to propose (and develop) two new options:
GX: Always add new elements, but only update elements when the new score for an existing key is greater than the old score.
LX: Always add new elements, but only update elements when the new score for an existing key is less than the old score.
Background
I currently perform this operation via Lua script, but I'm ultimately interacting with Redis on an item-by-item basis. It would be far better if this could be done in bulk as a part of the ZADD function.
We use this functionality in order to treat Redis sorted sets as a time-based priority queue, typically with the score being a converted timestamp. The problem with the current options is that they are essentially all-or-nothing: with NX we can ensure that an item's priority cannot be changed, but it prevents us from reliably increasing that item's priority (in our case by lowering its score).