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).

Comment From: alexronke-channeladvisor

Note that I would like to be assigned this feature request. It is of value to myself and my employer, and I plan to develop it in the coming months. For maintenance purposes, we don't want to simply fork Redis entirely just for this one feature, so having it added to a future version once developed and tested would be a great help.

Comment From: itamarhaber

Hello @alexronke-channeladvisor

The use case sounds reasonable and the feature request shouldn't be too hard to implement. While we wait here for more feedback from the community and developers, WRT:

we don't want to simply fork Redis entirely just for this one feature

Instead, consider using vanilla Redis and just implement the logic with a custom Redis Module.

Comment From: alexronke-channeladvisor

Thanks. I was not previously aware of the modules capability.

In terms of standard practice, are modules developed in github repositories that are entirely independent? Or are they generally developed in forks of Redis itself?

Comment From: itamarhaber

You can review the modules API documentation, and specifically the intro for more information, but to;dr is that modules are shared libraries that implement the API. You don't need to fork Redis to use modules - their purpose is extending the vanilla flavor.

Comment From: alexronke-channeladvisor

Per a recommendation from @oranagra , the options are named GT and LT. Additionally, their usage does not change behavior with regard to new elements; they are thus able to be combined with the XX option.