redis / redis-rb

A Ruby client library for Redis
MIT License
3.98k stars 1.03k forks source link

Configure Rails redis_cache_store with redis 5 #1250

Closed adrys-lab closed 10 months ago

adrys-lab commented 10 months ago

After upgrading to redis 5 in rails 7.1.3, we are facing some issues on trying to replicate same configuration to configure Rails Redis Cache Store we used to have with previous redis 4 version.

This is what we used to have in our production initializer file: We faced 2 issues: 1- cluster is not allowed anymore and suggests to use redis-clustering gem, but we don't know how to innject it here for Rails Redis Cache Store. 2- it seems replica is not allowed anymore so we wonder where this configuration to indicate Redis to use Replicas should be placed.

  config.cache_store = :redis_cache_store, {
    cluster: ["redis://#{ENV['REDIS_CACHE_HOST']}:6379/0"],
    connect_timeout:    5, # Defaults to 20 seconds
    read_timeout:       0.5, # Defaults to 1 second
    write_timeout:      0.5, # Defaults to 1 second
    expires_in: 3.days,
    replica: true,
    pool: {
      size: ENV.fetch('RAILS_MAX_THREADS', 5),
      timeout: 0.5
    }
  }

can you help on replicating this same configuration into the new versions of redis + using the redis-clustering ?

On our tests we have done 2 tries without success: 1- replace cluster by url 2- remove replica config,

but this turned out in dropping down our available MAX CONNECTIONS

image
byroot commented 10 months ago

For advance uses you can use the block form of RedisCacheStore: https://api.rubyonrails.org/classes/ActiveSupport/Cache/RedisCacheStore.html#method-c-new

Then for how to instantiate the cluster client it's all in the readme: https://github.com/redis/redis-rb?tab=readme-ov-file#cluster-support