In my environment file, I have:
config.cache_store = :redis_cache_store, { url: ENV.fetch('REDIS_URL_CACHING', 'redis://localhost:6379/0')}
In rails console, if I print REDIS_URL_CACHING
, I get:
> ENV['REDIS_URL_CACHING']=> "redis://:mypassword@localhost:6379/0
However, if I want to check if rails is connected to redis, I get:
> Rails.cache.redis.keys=> falseirb(main):004:0> Rails.cache.redis.keysTraceback (most recent call last): 1: from (irb):4Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL))
My redis.conf file is like:
bind 0.0.0.0requirepass mypassword
What am I missing here?
If I remove password option, it's working, but my macBook gets attacked.
EDIT
In redis gem guide, you can set password for redis like the following:
redis = Redis.new(url: "redis://:p4ssw0rd@10.0.1.1:6380/15")# Or redis = Redis.new(password: "mysecret")# And thenredis.set("foo", "bar")redis.get("foo")
However, I'd like to use low-level caching in the way mentioned in the official low level caching guide
class Product < ApplicationRecord def competing_price Rails.cache.fetch("#{cache_key_with_version}/competing_price", expires_in: 12.hours) do Competitor::API.find_price(id) end endend
Can't figure out how I can config redis gem to use with Rails.cache.fetch