1
0
mirror of https://github.com/mastodon/mastodon synced 2024-12-24 11:38:18 +09:00
mastodon/app/lib/redis_connection.rb
2024-09-02 14:19:55 +00:00

46 lines
792 B
Ruby

# frozen_string_literal: true
class RedisConnection
class << self
def establish_pool(new_pool_size)
@pool&.shutdown(&:close)
@pool = ConnectionPool.new(size: new_pool_size) { new.connection }
end
delegate :with, to: :pool
def pool
@pool ||= establish_pool(pool_size)
end
def pool_size
if Sidekiq.server?
Sidekiq[:concurrency]
else
ENV['MAX_THREADS'] || 5
end
end
end
attr_reader :config
def initialize
@config = REDIS_CONFIGURATION.base
end
def connection
namespace = config[:namespace]
if namespace.present?
Redis::Namespace.new(namespace, redis: raw_connection)
else
raw_connection
end
end
private
def raw_connection
Redis.new(**config)
end
end