2020-01-26 17:01:34 +00:00
|
|
|
app_redis_config = {
|
2020-02-20 05:22:26 +00:00
|
|
|
url: URI.parse(ENV.fetch('REDIS_URL', 'redis://127.0.0.1:6379')),
|
|
|
|
password: ENV.fetch('REDIS_PASSWORD', nil).presence
|
2020-01-26 17:01:34 +00:00
|
|
|
}
|
2019-08-14 09:48:44 +00:00
|
|
|
|
2020-10-03 09:54:33 +00:00
|
|
|
if ENV['REDIS_SENTINELS'].presence
|
|
|
|
default_sentinel_port = '26379'
|
|
|
|
# expected format for REDIS_SENTINELS url string is host1:port1, host2:port2
|
|
|
|
sentinels = ENV['REDIS_SENTINELS'].split(',').map do |sentinel_url|
|
|
|
|
host, port = sentinel_url.split(':').map(&:strip)
|
|
|
|
{ host: host, port: port || default_sentinel_port, password: app_redis_config[:password] }
|
|
|
|
end
|
|
|
|
|
|
|
|
master_name = ENV.fetch('REDIS_SENTINEL_MASTER_NAME', 'mymaster')
|
|
|
|
# over-write redis url as redis://:<your-redis-password>@<master-name>/ when using sentinel
|
|
|
|
# more at https://github.com/redis/redis-rb/issues/531#issuecomment-263501322
|
|
|
|
app_redis_config[:url] = URI.parse("redis://#{master_name}")
|
|
|
|
app_redis_config[:sentinels] = sentinels
|
|
|
|
end
|
|
|
|
|
|
|
|
redis = Rails.env.test? ? MockRedis.new : Redis.new(app_redis_config)
|
2020-07-07 18:44:07 +00:00
|
|
|
# Alfred
|
2020-01-23 17:29:07 +00:00
|
|
|
# Add here as you use it for more features
|
2020-07-07 18:44:07 +00:00
|
|
|
# Used for Round Robin, Conversation Emails & Online Presence
|
2019-10-20 08:47:26 +00:00
|
|
|
$alfred = Redis::Namespace.new('alfred', redis: redis, warning: true)
|
2020-06-25 18:05:16 +00:00
|
|
|
|
|
|
|
# https://github.com/mperham/sidekiq/issues/4591
|
|
|
|
# TODO once sidekiq remove we can remove this
|
|
|
|
Redis.exists_returns_integer = false
|