it's my first time using rails,redis and sidekiq,and I have been facing this error all day and didn't reach any solution , I saw a lot solutions to this error but it didn't work for me, so I don't know where's the problem
when i try the end point sometimes i get this error and sometime i got another error like this >> NoMethodError (undefined method `HGET' for nil:NilClass):
my versions are ruby: '2.6.10' , rails: '5.2.8', mysql2 for database , windows 10
I have .env
REDIS_URL=redis:
then I created sideqik.rb , redis.rb files in config>initializers
sideqik.rb
Sidekiq.configure_server do |config|
config.redis = { url: ENV["REDIS_URL"] }
end
Sidekiq.configure_client do |config|
config.redis = { url: ENV["REDIS_URL"] }
end
redis.rb
$redis= Redis.new(url: ENV["REDIS_URL"])
# when i write redis without $ , I can't access it in controller or worker file so i don't know if this how I should define it or there's another way
and in config>application.rb inside application class i put this code
config.active_job.queue_adapter = :sidekiq
What I have tried:
I have tried to change the url in .env as some solutions said to 'redis:6379' but still same error, and when i change it to localhost:6379 i got error with rails server
also I tries to install
gem 'redis-rail'
and added this in env
config.cache_store = :redis_store, {
host: "localhost",
port: 6379,
db: 0,
password: "mysecret",
namespace: "cache"
} , {
expires_in: 90.minutes
}
but nothing happens and still the error as it
# while I was testing the end points the redis-server was running but nothing changed inside it