Skip to content

Commit

Permalink
Add host_to_name_map option to Dalli::Protocol::ConnectionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
philister committed May 7, 2024
1 parent 67942b8 commit 25d9bf0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/dalli/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class Client
# useful for injecting a FIPS compliant hash object.
# - :protocol - one of either :binary or :meta, defaulting to :binary. This sets the protocol that Dalli uses
# to communicate with memcached.
# - :host_to_name_map - a hash mapping "host:port" to a name. Useful for providing more descriptive names or
# tuning the ring-continuum e.g. { 'localhost:11211' => 'local' }
#
def initialize(servers = nil, options = {})
@normalized_servers = ::Dalli::ServersArgNormalizer.normalize_servers(servers)
Expand Down
7 changes: 5 additions & 2 deletions lib/dalli/protocol/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class ConnectionManager
# amount of time to sleep between retries when a failure occurs
socket_failure_delay: 0.1,
# Set keepalive
keepalive: true
keepalive: true,
# map a "host:port" to a specific name
host_to_name_map: {}
}.freeze

attr_accessor :hostname, :port, :socket_type, :options
Expand All @@ -45,7 +47,8 @@ def name
if socket_type == :unix
hostname
else
"#{hostname}:#{port}"
name = "#{hostname}:#{port}"
options[:host_to_name_map][name].presence || name
end
end

Expand Down

0 comments on commit 25d9bf0

Please sign in to comment.