gpt4 book ai didi

ruby-on-rails - 从 Ruby 到 Azure 的 Redis::TimeoutError

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

我正在尝试从 Ruby on Rails 访问 Azure Redis 缓存服务。我安装了 gem 'redis' (3.1.0)。我想使用 SSL 来完成此任务。

这是我在 config/initializers/redis.rb

中的代码
$redis = Redis.new(:host => '[APP_NAME].redis.cache.windows.net', :port => 6380, :db => 10)
$redis.auth("[ACCESS_TOKEN]")

然后,我运行 rails c 并在 auth 调用中 100% 收到“连接超时”消息。我在 .NET 中工作,所以我不确定为什么它在这里失败。

/home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:55:in `rescue in _read_from_socket': Connection timed out (Redis::TimeoutError)
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:48:in `_read_from_socket'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:41:in `gets'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/connection/ruby.rb:273:in `read'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:238:in `block in read'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:226:in `io'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:237:in `read'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:102:in `block in call'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:207:in `block (2 levels) in process'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:329:in `ensure_connected'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:197:in `block in process'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:279:in `logging'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:196:in `process'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:102:in `call'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:87:in `block in connect'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:266:in `with_reconnect'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:84:in `connect'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:326:in `ensure_connected'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:197:in `block in process'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:279:in `logging'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:196:in `process'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis/client.rb:102:in `call'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis.rb:64:in `block in auth'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis.rb:37:in `block in synchronize'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis.rb:37:in `synchronize'
from /home/vagrant/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/redis-3.1.0/lib/redis.rb:63:in `auth'
from /vagrant/dragondoor/config/initializers/redis.rb:3:in `<top (required)>'

最佳答案

这有效:

Gemfile中:

gem 'redis', github: 'RedisLabs/redis-rb', branch: 'ssl'

config/initializers/redis.rb

$redis = Redis.new(:host => '[APP_NAME].redis.cache.windows.net', :port => 6380, :db => 10, :password => "[ACCESS_TOKEN]", :use_ssl => true)

关于ruby-on-rails - 从 Ruby 到 Azure 的 Redis::TimeoutError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29981213/

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