我的Redis在后台运行,但是显然Sidekiq没有连接到它。有任何想法吗?
我运行后:ps aux | grep redis
redis 21875 0.2 0.0 42044 6208 ? Ssl 17:47 0:00 /usr/local/bin/redis-server 127.0.0.1:6379
运行bundle exec sidekiq
之后的控制台:
2018-08-09T13:47:23.416Z 18487 TID-gpqfvm843 INFO: Running in ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
2018-08-09T13:47:23.416Z 18487 TID-gpqfvm843 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2018-08-09T13:47:23.416Z 18487 TID-gpqfvm843 INFO: Upgrade to Sidekiq Pro for more features and support: http://sidekiq.org
2018-08-09T13:47:23.416Z 18487 TID-gpqfvm843 INFO: Booting Sidekiq 5.1.3 with redis options {:id=>"Sidekiq-server-PID-18487", :url=>nil}
2018-08-09T13:47:23.418Z 18487 TID-gpqfvm843 INFO: Starting processing, hit Ctrl-C to stop
ERROR: Error fetching job: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)
2018-08-09T15:44:33.642Z 21107 TID-gn2775u13 WARN: Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)
2018-08-09T15:44:33.642Z 21107 TID-gn2775u13 WARN: /usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:344:in `rescue in establish_connection'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:328:in `establish_connection'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:99:in `block in connect'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:291:in `with_reconnect'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:98:in `connect'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:363:in `ensure_connected'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:219:in `block in process'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:304:in `logging'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:218:in `process'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:118:in `call'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:207:in `block in call_with_timeout'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:278:in `with_socket_timeout'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis/client.rb:206:in `call_with_timeout'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis.rb:1162:in `block in _bpop'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis.rb:45:in `block in synchronize'
/usr/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis.rb:45:in `synchronize'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis.rb:1159:in `_bpop'
/usr/lib/ruby/gems/2.5.0/gems/redis-4.0.1/lib/redis.rb:1204:in `brpop'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/fetch.rb:36:in `block in retrieve_work'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq.rb:95:in `block in redis'
/usr/lib/ruby/gems/2.5.0/gems/connection_pool-2.2.1/lib/connection_pool.rb:64:in `block (2 levels) in with'
/usr/lib/ruby/gems/2.5.0/gems/connection_pool-2.2.1/lib/connection_pool.rb:63:in `handle_interrupt'
/usr/lib/ruby/gems/2.5.0/gems/connection_pool-2.2.1/lib/connection_pool.rb:63:in `block in with'
/usr/lib/ruby/gems/2.5.0/gems/connection_pool-2.2.1/lib/connection_pool.rb:60:in `handle_interrupt'
/usr/lib/ruby/gems/2.5.0/gems/connection_pool-2.2.1/lib/connection_pool.rb:60:in `with'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq.rb:92:in `redis'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/fetch.rb:36:in `retrieve_work'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:91:in `get_one'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:101:in `fetch'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:84:in `process_one'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/processor.rb:73:in `run'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:16:in `watchdog'
/usr/lib/ruby/gems/2.5.0/gems/sidekiq-5.1.3/lib/sidekiq/util.rb:25:in `block in safe_thread'
2018-08-09T15:47:38.157Z 21107 TID-gn2775jy3 INFO: Redis is online, 3.756701478 sec downtime
2018-08-09T15:47:38.158Z 21107 TID-gn2775kvb INFO: Redis is online, 3.754789237 sec downtime
2018-08-09T15:47:38.158Z 21107 TID-gn2775ssv INFO: Redis is online, 3.753108879 sec downtime
2018-08-09T15:47:38.159Z 21107 TID-gn2775jdj INFO: Redis is online, 3.755684686 sec downtime
2018-08-09T15:47:38.159Z 21107 TID-gn2775uan INFO: Redis is online, 3.757379042 sec downtime
2018-08-09T15:47:38.257Z 21107 TID-gn2775u8z INFO: Redis is online, 3.854296004 sec downtime
2018-08-09T15:47:38.257Z 21107 TID-gn2775jlf INFO: Redis is online, 3.852340158 sec downtime
2018-08-09T15:47:38.257Z 21107 TID-gn2775j8r INFO: Redis is online, 3.861582112 sec downtime
2018-08-09T15:47:38.257Z 21107 TID-gn2775tq3 INFO: Redis is online, 3.853531228 sec downtime
2018-08-09T15:47:38.358Z 21107 TID-gn2775iw3 INFO: Redis is online, 3.958614643 sec downtime
2018-08-09T15:47:38.458Z 21107 TID-gn2775uff INFO: Redis is online, 4.053228399 sec downtime
2018-08-09T15:47:38.458Z 21107 TID-gn2775uzz INFO: Redis is online, 4.057391013 sec downtime
2018-08-09T15:47:38.459Z 21107 TID-gn2775unb INFO: Redis is online, 4.056936247 sec downtime
2018-08-09T15:47:38.459Z 21107 TID-gn2775j0v INFO: Redis is online, 4.063074372 sec downtime
2018-08-09T15:47:38.558Z 21107 TID-gn2775txz INFO: Redis is online, 4.159429111 sec downtime
2018-08-09T15:47:38.558Z 21107 TID-gn2775jn3 INFO: Redis is online, 4.158452973 sec downtime
2018-08-09T15:47:38.557Z 21107 TID-gn2775u13 INFO: Redis is online, 4.157790827 sec downtime
在Rails中配置:
/config/environments/development.rb
config.cache_store = :redis_store, 'redis://localhost:6379/0'
/config/initializers/sidekiq.rb
require 'sidekiq'
require 'sidekiq-status'
Sidekiq.configure_client do |config|
config.redis = { :size => 1 } #, url: ENV['REDIS_URL']
# accepts :expiration (optional)
Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes
config.redis = { url: 'redis://localhost:6379/0' }
end
Sidekiq.configure_server do |config|
# accepts :expiration (optional)
Sidekiq::Status.configure_server_middleware config, expiration: 30.minutes
# accepts :expiration (optional)
Sidekiq::Status.configure_client_middleware config, expiration: 30.minutes
config.redis = { url: 'redis://localhost:6379/0' }
end
/config/initializers/redis.rb
Redis.current = Redis.new(:host => '127.0.0.1', :port => 6379)
答案 0 :(得分:1)
此行表示Sidekiq确实已连接到它。我想您是同时启动Redis和Sidekiq的,而Redis花了几秒钟才可用?
2018-08-09T15:47:38.558Z 21107 TID-gn2775jn3信息:Redis处于在线状态,停机时间为4.158452973秒