mirror of https://github.com/mastodon/mastodon
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
792 B
Ruby
46 lines
792 B
Ruby
3 years ago
|
# frozen_string_literal: true
|
||
|
|
||
4 months ago
|
class RedisConnection
|
||
3 years ago
|
class << self
|
||
3 years ago
|
def establish_pool(new_pool_size)
|
||
|
@pool&.shutdown(&:close)
|
||
|
@pool = ConnectionPool.new(size: new_pool_size) { new.connection }
|
||
|
end
|
||
|
|
||
2 years ago
|
delegate :with, to: :pool
|
||
3 years ago
|
|
||
|
def pool
|
||
3 years ago
|
@pool ||= establish_pool(pool_size)
|
||
3 years ago
|
end
|
||
|
|
||
|
def pool_size
|
||
|
if Sidekiq.server?
|
||
2 years ago
|
Sidekiq[:concurrency]
|
||
3 years ago
|
else
|
||
|
ENV['MAX_THREADS'] || 5
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
4 months ago
|
attr_reader :config
|
||
|
|
||
|
def initialize
|
||
|
@config = REDIS_CONFIGURATION.base
|
||
|
end
|
||
|
|
||
3 years ago
|
def connection
|
||
4 months ago
|
namespace = config[:namespace]
|
||
|
if namespace.present?
|
||
3 years ago
|
Redis::Namespace.new(namespace, redis: raw_connection)
|
||
|
else
|
||
|
raw_connection
|
||
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def raw_connection
|
||
4 months ago
|
Redis.new(**config)
|
||
3 years ago
|
end
|
||
|
end
|