title: Rails cache store: how to configure redis_cache_store with password
body: <p>In my environment file, I have:</p>
  <pre class="lang-rb prettyprint-override"><code>config.cache_store = :redis_cache_store, { url: ENV.fetch('REDIS_URL_CACHING', 'redis://localhost:6379/0')}
  </code></pre>
  <p>In rails console, if I print <code>REDIS_URL_CACHING</code>, I get:</p>
  <pre class="lang-rb prettyprint-override"><code>&gt; ENV['REDIS_URL_CACHING']
  =&gt; &quot;redis://:mypassword@localhost:6379/0
  </code></pre>
  <p>However, if I want to check if rails is connected to redis, I get:</p>
  <pre class="lang-rb prettyprint-override"><code>&gt; Rails.cache.redis.keys
  =&gt; false
  irb(main):004:0&gt; Rails.cache.redis.keys
  Traceback (most recent call last):
          1: from (irb):4
  Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::EADDRNOTAVAIL))
  </code></pre>
  <p>My redis.conf file is like:</p>
  <pre><code>bind 0.0.0.0
  requirepass mypassword
  </code></pre>
  <p>What am I missing here?</p>
  <p>If I remove password option, it's working, but my macBook <a href="https://stackoverflow.com/questions/61931292/what-is-redis-change-its-own-configurations">gets attacked</a>.</p>
  <h1>EDIT</h1>
  <p>In <a href="https://github.com/redis/redis-rb" rel="nofollow noreferrer">redis gem guide</a>, you can set password for redis like the following:</p>
  <pre class="lang-rb prettyprint-override"><code>redis = Redis.new(url: &quot;redis://:p4ssw0rd@10.0.1.1:6380/15&quot;)
  # Or 
  redis = Redis.new(password: &quot;mysecret&quot;)
  
  # And then
  redis.set(&quot;foo&quot;, &quot;bar&quot;)
  redis.get(&quot;foo&quot;)
  </code></pre>
  <p>However, I'd like to use low-level caching in the way mentioned in the <a href="https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching" rel="nofollow noreferrer">official low level caching guide</a></p>
  <pre class="lang-rb prettyprint-override"><code>class Product &lt; ApplicationRecord
    def competing_price
      Rails.cache.fetch(&quot;#{cache_key_with_version}/competing_price&quot;, expires_in: 12.hours) do
        Competitor::API.find_price(id)
      end
    end
  end
  </code></pre>
  <p>Can't figure out how I can config redis gem to use with <code>Rails.cache.fetch</code></p>