使用Redis更改Rails上的数据时出错

时间:2019-05-20 11:52:05

标签: ruby-on-rails ruby redis

有时,在击中任何给定的api端点时,有时某个对象会在数据库中更新,这会引发一些我在下面提到的错误。

getaddrinfo: nodename nor servname provided, or not known
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:177:in `getaddrinfo'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:177:in `connect'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:260:in `connect'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:336:in `establish_connection'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:101:in `block in connect'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:293:in `with_reconnect'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:100:in `connect'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:364:in `ensure_connected'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:221:in `block in process'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:306:in `logging'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:220:in `process'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:187:in `call_pipelined'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:157:in `block in call_pipeline'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:293:in `with_reconnect'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis/client.rb:155:in `call_pipeline'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis.rb:2299:in `block in multi'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis.rb:58:in `block in synchronize'
/Users/xyz/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis.rb:58:in `synchronize'
/Users/xyz/.rvm/gems/ruby-2.3.0/gems/redis-3.3.0/lib/redis.rb:2291:in `multi'

Ruby版本-2.3.0 Rails版本-4.2.5 Redis版本-3.3.0

options[:url] = ENV["REDISCLOUD_URL"]
$redis = Redis::Namespace.new("hello:#{Rails.env}", redis: Redis.new(options))

这是它的使用方式。我已将ENV [“ REDISCLOUD_URL”]设置为第一个localhost URL'redis://127.0.0.1:6379',然后设置为实际的云URL,但无济于事。

0 个答案:

没有答案