我正在尝试从Ruby on Rails访问Azure Redis缓存服务。我有宝石' 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)>'
答案 0 :(得分:2)
这有效:
在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)