Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host_to_name_map option to Dalli::Protocol::ConnectionManager #1005

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 10 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,13 @@ def name
if socket_type == :unix
hostname
else
"#{hostname}:#{port}"
name = "#{hostname}:#{port}"

if options[:host_to_name_map][name].nil?
name
else
options[:host_to_name_map][name]
end
end
end

Expand Down