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.
Class Method Summary collapse
- .build_from_client(client) ⇒ Object
- .build_from_host_port(host, port) ⇒ Object
- .build_from_uri(uri) ⇒ Object
- .hashify(node_key) ⇒ Object
- .split(node_key) ⇒ Object
Class Method Details
.build_from_client(client) ⇒ Object
55 56 57 |
# File 'lib/redis_client/cluster/node_key.rb', line 55 def build_from_client(client) "#{client.config.host}#{DELIMITER}#{client.config.port}" end |
.build_from_host_port(host, port) ⇒ Object
51 52 53 |
# File 'lib/redis_client/cluster/node_key.rb', line 51 def build_from_host_port(host, port) "#{host}#{DELIMITER}#{port}" end |
.build_from_uri(uri) ⇒ Object
45 46 47 48 49 |
# File 'lib/redis_client/cluster/node_key.rb', line 45 def build_from_uri(uri) return '' if uri.nil? "#{uri.host}#{DELIMITER}#{uri.port}" end |
.hashify(node_key) ⇒ Object
15 16 17 18 |
# File 'lib/redis_client/cluster/node_key.rb', line 15 def hashify(node_key) host, port = split(node_key) { host: host, port: port } end |
.split(node_key) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/redis_client/cluster/node_key.rb', line 20 def split(node_key) return [node_key, nil] if node_key.nil? || node_key.empty? bracketed = split_bracketed(node_key) return bracketed unless bracketed.nil? pos = node_key.rindex(DELIMITER, -1) return [node_key, nil] if pos.nil? [node_key[0, pos], node_key[(pos + 1)..]] end |