Rails, Redis and Sentinel

I have a Redis cluster of 4 nodes, 1 master and 3 slaves, controlled by Sentinel.

Now in rails, I need to connect to this cluster, reading from the nearest replica and writing to master, just like with MongoDB.

Using a stone redis-rails

, how can one be configured cache_store

to point Guardians instead of a single node?

+3


source to share


1 answer


I may have missed it, but I didn't know that you can configure it to read from subordinates? However, this is my master + 2 slave config:

config.cache_store = :redis_store, {
    url: 'redis://prestwick/1',
    sentinels: [{host: 'prestwick.i', port: 26379}, {host: 'carnoustie.i', port: 26379}, {host: 'birkdale.i', port: 26379}],
    role: 'master',
    expires_in: 1.hour
  }

      



And in case it's helpful, my config for the REDIS and Sidekiq shared object (this is in config / initializers / 001_redis.rb):

redis_options = {
  url: 'redis://prestwick/0',
  sentinels: [{host: 'prestwick.i', port: 26379}, {host: 'carnoustie.i', port: 26379}, {host: 'birkdale.i', port: 26379}],
  role: 'master'
}
redis_sidekiq_options = {
  url: 'redis://prestwick/2',
  sentinels: [{host: 'prestwick.i', port: 26379}, {host: 'carnoustie.i', port: 26379}, {host: 'birkdale.i', port: 26379}],
  role: 'master'
}

REDIS = Redis.new(redis_options)

Sidekiq.configure_server do |config|
  config.redis = redis_sidekiq_options
end
Sidekiq.configure_client do |config|
  config.redis = redis_sidekiq_options
end

      

+4


source







All Articles