简体   繁体   English

Redis ZPOP的实现

[英]Implementation of Redis ZPOP

I'm searching for Redis ZPOP implementation for popping ZSET element atomically, the most common answer is like:我正在寻找用于以原子方式弹出 ZSET 元素的 Redis ZPOP 实现,最常见的答案是:

WATCH zset
element = ZRANGE zset 0 0
MULTI
    ZREM zset element
EXEC

I wonder if the following implementation can do the same job, which seems simpler?我想知道下面的实现是否可以做同样的工作,哪个看起来更简单? Or does it has bugs or performance problems?或者它有错误或性能问题?

MULTI
    element = ZRANGE zset 0 0
    ZREM zset element
EXEC

The call to ZRANGE inside the MULTI block will only be returned after the EXEC, so the 2nd version will not work as expected. MULTI 块内对 ZRANGE 的调用只会在 EXEC 之后返回,因此第二个版本将无法按预期工作。

For your information, as of Redis v5, the commands ZPOPMIN and ZPOPMAX have been added.供您参考,从 Redis v5 开始,已添加命令 ZPOPMIN 和 ZPOPMAX。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM