Module: RedisClient::Cluster::NodeKey

Defined in:
lib/redis_client/cluster/node_key.rb

Overview

Node key’s format is ‘<ip>:<port>`. It is different from node id. Node id is internal identifying code in Redis Cluster.

Constant Summary collapse

DELIMITER =
':'

Class Method Summary collapse

Class Method Details

.build_from_client(client) ⇒ Object



35
36
37
# File 'lib/redis_client/cluster/node_key.rb', line 35

def build_from_client(client)
  "#{client.config.host}#{DELIMITER}#{client.config.port}"
end

.build_from_host_port(host, port) ⇒ Object



31
32
33
# File 'lib/redis_client/cluster/node_key.rb', line 31

def build_from_host_port(host, port)
  "#{host}#{DELIMITER}#{port}"
end

.build_from_uri(uri) ⇒ Object



25
26
27
28
29
# File 'lib/redis_client/cluster/node_key.rb', line 25

def build_from_uri(uri)
  return '' if uri.nil?

  "#{uri.host}#{DELIMITER}#{uri.port}"
end

.hashify(node_key) ⇒ Object



13
14
15
16
# File 'lib/redis_client/cluster/node_key.rb', line 13

def hashify(node_key)
  host, port = split(node_key)
  { host: host, port: port }
end

.split(node_key) ⇒ Object



18
19
20
21
22
23
# File 'lib/redis_client/cluster/node_key.rb', line 18

def split(node_key)
  pos = node_key&.rindex(DELIMITER, -1)
  return [node_key, nil] if pos.nil?

  [node_key[0, pos], node_key[(pos + 1)..]]
end