gpt4 book ai didi

ruby-on-rails - ruby 和 Redis : set a timeout for subscribtions

转载 作者:IT王子 更新时间:2023-10-29 06:00:24 26 4
gpt4 key购买 nike

我想在 Redis channel 中等待消息最多 2 秒,然后我希望订阅过期/超时并停止阻止我的代码。

redis = Redis.new

redis.subscribe(channel) do |on|
on.message do |channel, message|
# ...
end
end

# This line is never reached if no message is sent to channel :(

我正在使用 https://github.com/redis/redis-rb .我在源代码中搜索但没有找到订阅超时选项。

最佳答案

您现在可以 subscribe with a timeout一步到位:

redis.subscribe_with_timeout(5, channel) do |on|
on.message do |channel, message|
# ...
end
end

关于ruby-on-rails - ruby 和 Redis : set a timeout for subscribtions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26624349/

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