You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brian O'Rourke edited this page Apr 12, 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.
Back when Redis.current was introduced, Ruby applications were rarely using threads, so a single global client made some things simpler. But most modern applications now use threads, so having a single client is an anti-pattern.
It is expected that end-users implement their own mechanism such as this 'RedisConnection' utility function
moduleRedisConnectionextendselfdefredis_config@redis_config ||= Rails.application.config_for(:redis)enddefcurrent@current ||= Redis.new(redis_config)enddefcurrent=(redis)@current=redisenddefok?current.ping == "PONG"rescueRedis::BaseConnectionError=>ewarn"could not connect to redis: #{e.inspect}"falseendend