Is there good way to support pop members from the Redis Sorted Set?

Viewed 2339

Is there good way to support pop members from the Redis Sorted Set just like the api LPOP of the List ?

What I figured out for poping message from the Redis Sorted Set is using ZRANGE +ZREM , however it is not thread security and need the distributed lock when multi threads accessing them at the same time from the different host.

Please kind suggesting if there is better way to pop the members from the Sorted Set?

2 Answers

In Redis 5.0 or above, you can use [B]ZPOP{MIN|MAX} key [count] for this scenario.

The MIN version takes the item(s) with the lowest scores; MAX takes the item(s) with the highest scores. count defaults to 1, and the B prefix blocks until the data is available.

Related