Skip to content

Commit

Permalink
THREESCALE-10826: Connect to Redis through Unix socket (#3927)
Browse files Browse the repository at this point in the history
* Allow `unix` sockets as Redis URls
  • Loading branch information
jlledom authored Oct 22, 2024
1 parent 4756564 commit e803d12
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/lib/three_scale/redis_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e803d12

Please sign in to comment.