The problem/use-case that the feature addresses

I'm trying to pop a certain amount of elements by a sprcific score from a sorted set. The use case I have is that I have set containing jobs with priorities, and I need to get X amount of jobs from a specific priority according to amount of available threads.

Description of the feature

few solutions: 1. ZGETRANGEBYSCORE to have a boolean flag that would return the removed elements instead of number of elements removed 2. ZMPOP with SCORE flag or SCORE_RENGE 3. ZREMRANGEBYSCORE with COUNT flag so it would be possible to get and then remove in MULTI

Alternatives you've considered

there's ZMPOP which gets MIN | MAX and LIMIT but it doesn't get the elements from a specific score but all the elements (up until count elements) sorted from max -> min or vice versa (same with ZPOPMAX / ZPOPMIN) I also thought about doing a MULTI with ZGETRANGEBYSCORE and give the required score as MIN and MAX and it has count but unfortunately ZREMRANGEBYSCORE does not have COUNT parameter so using it will delete the required elements + all the remaining elements with this score

Comment From: itamarhaber

Hi @zalts1,

Thanks for suggesting these features. I agree that what you're trying to achieve isn't available as a single atomic operation in Redis. As a rule, the project attempts to avoid bloat by including only the most commonly needed functionality in form of commands. To accommodate "niche" requirements, there's Lua programmability (see https://www.reddit.com/r/redis/comments/10kvs2v/get_and_delete_elements_from_sorted_set/).

The question here, IMO, is whether the pattern you're describing is a) correct and b) common. Personally, I can't find anything wrong with it, and there's #180 that supports the need :)

Some impressions:

WRT 1 - I assume you meant ZREMRANGEBYSCORE. If that is the case, we try to avoid having reply types depend on arguments to commands, so adding a flag that makes the command respond with an array instead of an integer is less desirable.

Option 2 may work, but I find it weird to "pop" from the middle. Maybe it is just me.

Option 3 appears the most promising IMO, but it means we'll also need a "REV" variant.

Comment From: zuiderkwast

@itamarhaber "pop from the middle" sounds strange indeed. What about "cut"? In the linked issue, Oran suggested ZPOPRANGEBYSCORE. Maybe ZCUTRANGEBYSCORE is better?

Comment From: itamarhaber

Also #8836

Comment From: ranshid

@itamarhaber Not sure it is a good suggestion but do we also want to support the blocking version of these new commands?

Comment From: ag-TJNII

👍 for this. I have a case where I'm using a sorted set for batching. I want to pop (not fetch) all records below a certain score, because above that score the records will be incomplete. Not having a score threshold on ZPOPMIN / ZPOPMAX while there are multiple fetch commands with score boundaries feels like a feature gap to me.