Rails,Redis和Sentinel

6
我有一个由1个主节点和3个从节点组成的Redis集群,并由Sentinel进行监控。
现在在rails中,我需要连接到这个集群,从最近的副本读取,写入主节点,就像我使用MongoDB一样。
使用redis-rails gem,如何配置cache_store以指定Sentinels而不是单个节点?
1个回答

9

我可能错过了,但我不知道您是否可以将其配置为从从服务器读取?但是,这是我的主服务器+2个从服务器的配置:

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
  }

如果有用的话,这是我为一般REDIS对象和Sidekiq进行配置的(这在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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接