gpt4 book ai didi

ruby-on-rails - 如何从 Redis 排序集中弹出?

转载 作者:IT王子 更新时间:2023-10-29 06:14:59 25 4
gpt4 key购买 nike

我使用 Redis 排序集作为队列来维护用户列表,我需要弹出列表中的第一项并使用它,但我遇到了问题。这是我的尝试...

keys = []
$redis.multi do
# Get the item at the top of the sorted set
keys = $redis.zrange("users:waiting", 0, 0)

# Remove it from the set
$redis.zrem("users:waiting", keys[0])
end

# Get the item from the range
@user_id = keys[0]

...但是这段代码行不通。帮助!预先感谢您的智慧!

最佳答案

它不起作用的原因是因为 MULTI。

键未分配。最后调用 EXEC 是在返回这些结果时

参见 https://github.com/redis/redis-rb#executing-commands-atomically

就在它下面https://github.com/redis/redis-rb#futures

应该显示差异 :) 如果这不完全正确,我深表歉意,因为我不使用 Ruby。

关于ruby-on-rails - 如何从 Redis 排序集中弹出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25880566/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com