簡體   English   中英

如何從Redis排序集中彈出?

[英]How can I pop from a Redis sorted set?

我正在使用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不能完全正確的話,那么表示歉意。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM