Skip to content

Instantly share code, notes, and snippets.

@andywenk
Created September 23, 2014 10:48
Show Gist options
  • Save andywenk/409650ae4dd3a33f3863 to your computer and use it in GitHub Desktop.
Save andywenk/409650ae4dd3a33f3863 to your computer and use it in GitHub Desktop.
redis configuration for redis-sentinel and redis-session-store
######### redis configuration #########
### redis sentinel und sidekiq
# https://github.com/flyerhzm/redis-sentinel
# http://tom.meinlschmidt.org/2013/12/20/redis-sentinel-with-ruby-on-rails/
sentinels = {
development:
[
{ host: "127.0.0.1", port: 6379 }
],
preview:
[
{ host: "x.x.x.41", port: 26379 },
{ host: "x.x.x.41", port: 26380 },
{ host: "x.x.x.30", port: 26379}
]
}
redis_connection = proc {
Redis.current = Redis.new(master_name: "mymaster", sentinels: sentinels[Rails.env], db: APP_CONFIG[:redis][:db])
}
redis = ConnectionPool.new(size: 10, &redis_connection)
Sidekiq.configure_server do |config|
config.redis = redis
end
Sidekiq.configure_client do |config|
config.redis = redis
end
### redis session store
# https://github.com/roidrage/redis-session-store
Ace::Application.config.session_store :redis_session_store, {
key: APP_CONFIG[:session][:redis][:key],
serializer: APP_CONFIG[:session][:redis][:serializer].to_sym, #hybrid
on_redis_down: -> (*a) { logger.error("Redis down! #{a.inspect}") }, #fix me!
on_session_load_error: -> (*a) { logger.error("Redis Session load error! #{a.inspect}") }, #fix me!
redis: {
db: APP_CONFIG[:session][:redis][:db],
expire_after: "#{APP_CONFIG[:session][:redis][:expire_after]}".to_i.minutes, # 120.minutes
key_prefix: APP_CONFIG[:session][:redis][:key_prefix], # 'ace:'
host: APP_CONFIG[:session][:redis][:host], # '127.0.0.1'
port: APP_CONFIG[:session][:redis][:port], # 6379
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment