-
Notifications
You must be signed in to change notification settings - Fork 1k
Connection Management
Benjamin Fleischer edited this page Apr 5, 2022
·
4 revisions
Beginning in Redis 5.0, with the removal of Redis.current, Redis no longer provides a mechanism for managing a global connection
It is expected that end-users implement their own mechanism such as this 'RedisConnection' utility function
module RedisConnection
extend self
def redis_config
@redis_config ||= Rails.application.config_for(:redis).merge(
# per https://devcenter.heroku.com/articles/securing-heroku-redis
ssl_params: {verify_mode: OpenSSL::SSL::VERIFY_NONE},
)
end
def current
@current ||= Redis.new(redis_config)
end
def current=(redis)
@current = redis
end
def ok?
current.ping == "PONG"
rescue Redis::BaseConnectionError => e
warn "could not connect to redis: #{e.inspect}"
false
end
end