From e803d12370959c3eaefd7f076098b700af5ea8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Lled=C3=B3?= Date: Tue, 22 Oct 2024 14:40:29 +0200 Subject: [PATCH] THREESCALE-10826: Connect to Redis through Unix socket (#3927) * Allow `unix` sockets as Redis URls --- app/lib/three_scale/redis_config.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/lib/three_scale/redis_config.rb b/app/lib/three_scale/redis_config.rb index c9f0823fd8..b6bbc9f8a9 100644 --- a/app/lib/three_scale/redis_config.rb +++ b/app/lib/three_scale/redis_config.rb @@ -5,9 +5,7 @@ class RedisConfig def initialize(redis_config = {}) raw_config = (redis_config || {}).deep_symbolize_keys raw_config.delete_if { |_key, value| value.blank? } - uri = URI.parse(raw_config[:url].to_s) - raw_config[:db] ||= uri.path[1..] - raw_config[:ssl] ||= true if uri.scheme == 'rediss' + parse_uri(raw_config) apply_sentinels_config!(raw_config) raw_config.compact! @@ -40,6 +38,17 @@ def respond_to_missing?(method_sym, *args) DEFAULT_SENTINEL_PORT = 26379 + def parse_uri(raw_config) + uri = URI.parse(raw_config[:url].to_s) + if uri.scheme == 'unix' + raw_config[:path] ||= uri.path + raw_config[:url] = nil + else + raw_config[:db] ||= uri.path[1..] + raw_config[:ssl] ||= true if uri.scheme == 'rediss' + end + end + def apply_sentinels_config!(config) sentinels = config.delete(:sentinels).presence return unless sentinels