Propsal: Redis Cluster support in ActiveSupport cache

Hi, I notice that in ActiveSupport Cache, the redis-rb v5 gem is supported. However, Redis Cluster is not supported since the client would raise an exception when operations like mget is called.

For example, in read_multi_mget, it is possible to perform a pipeline of get commands instead since the underlying gem redis-cluster-client would internally fan-out and gather the response from multiple Redis nodes. Likewise for multi-key del in delete_multi_entries.

Would it make sense to add support for it within ActiveSupport::Cache::RedisCacheStore?

Hello,

The version 0.9.0 of redis-cluster-client was released. It made MSET, MGET and DEL commands able to pass multiple keys without a hashtag to prevent cross-slot errors by using pipelining. I’d say that it’s useful in the use case, but the performance is degradated than an original MGET. I think it might work if we pass an instance of redis-clustering client to ActiveSupport cache.

1 Like

I was taught a usage of a session store with redis-clustering gem by a Rails maintainer.

config.session_store :cache_store, cache: ActiveSupport::Cache::RedisCacheStore.new(redis: Redis::Cluster.new(nodes: %w[redis://your-host:6379]))

Thank you for the link and also the changes to redis-cluster-client that made this possible!

Gitlab is already passing the Redis::Cluster into the ActiveSupport::Cache::RedisCacheStore via the redis key (lib/gitlab/redis/cache.rb · 59170ff492736ae059d6f7f050685d5553ca4f9f · GitLab.org / GitLab · GitLab). This means we could drop the use of our patch lib/gitlab/patch/redis_cache_store.rb · 59170ff492736ae059d6f7f050685d5553ca4f9f · GitLab.org / GitLab · GitLab.

For other Rails users, the link you attached above would guide them with configuring ActiveSupport::Cache::RedisCacheStore with a Redis Cluster.

I think this thread can be closed if that is the case.