Railsアプリの仕様を実行するためにwerckerを使用しています。werckerでredisを設定するのに問題があります。私のRailsアプリでは、redis.rb
これは次のようになります:
if Figaro.env.rediscloud_url
uri = URI.parse(Figaro.env.rediscloud_url)
REDIS = Redis.new(Host: uri.Host, port: uri.port, password: uri.password)
elsif ENV['WERCKER_REDIS_Host'] && ENV['WERCKER_REDIS_PORT']
REDIS = Redis.new(Host: ENV['WERCKER_REDIS_Host'], port: ENV['WERCKER_REDIS_PORT'])
else
REDIS = Redis.new
end
Werckerでは、WERCKER_REDIS_Host
環境変数を127.0.0.1
に設定し、WERCKER_REDIS_PORT
を6379
に設定しました。
スペックを開始すると、次のように返されます。
Redis::CannotConnectError:
Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:332:in `rescue in establish_connection'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:318:in `establish_connection'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:178:in `call_pipelined'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:150:in `block in call_pipeline'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:148:in `call_pipeline'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:2245:in `block in multi'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:2237:in `multi'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/sidekiq-4.1.0/lib/sidekiq/client.rb:171:in `block in raw_Push'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:64:in `block (2 levels) in with'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `handle_interrupt'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:63:in `block in with'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `handle_interrupt'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/connection_pool-2.2.0/lib/connection_pool.rb:60:in `with'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/sidekiq-4.1.0/lib/sidekiq/client.rb:170:in `raw_Push'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/sidekiq-4.1.0/lib/sidekiq/client.rb:67:in `Push'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/sidekiq-4.1.0/lib/sidekiq/worker.rb:115:in `client_Push'
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/sidekiq-4.1.0/lib/sidekiq/extensions/generic_proxy.rb:19:in `method_missing'
# ./app/models/user.rb:26:in `send_reset_password_instructions'
# ./spec/models/user_spec.rb:43:in `block (3 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# IO::EINPROGRESSWaitWritable:
# Operation now in progress - connect(2) would block
# /pipeline/cache/bundle-install/Ruby/2.3.0/gems/redis-3.2.2/lib/redis/connection/Ruby.rb:122:in `connect_addrinfo'
どうすれば修正できますか?
私は同じ問題を抱えていましたが、修正を見つけました:
ターミナルでredis-server
を使用してRedisを手動で起動します
Redis-serverのインストールも必要になる場合があります
$ Sudo apt install redis-server