Module: Valkey::Commands::ClusterCommands
- Included in:
- Valkey::Commands
- Defined in:
- lib/valkey/commands/cluster_commands.rb
Overview
This module contains commands related to Redis Cluster management.
Constant Summary collapse
- CLUSTER_FAILOVER_MODES =
Valid modes for CLUSTER FAILOVER: FORCE, TAKEOVER.
%i[force takeover].freeze
Instance Method Summary collapse
-
#asking ⇒ String
Send ASKING command to the server.
-
#cluster_addslots(*slots) ⇒ String
Add slots to the cluster.
-
#cluster_addslotsrange(start_slot, end_slot) ⇒ String
Add a range of slots to the cluster.
-
#cluster_bumpepoch ⇒ String
Bump the epoch of the cluster.
-
#cluster_count_failure_reports(node_id) ⇒ Integer
Count failure reports for a node.
-
#cluster_countkeysinslot(slot) ⇒ Integer
Count keys in a specific slot.
-
#cluster_delslots(*slots) ⇒ String
Delete slots from the cluster.
-
#cluster_delslotsrange(start_slot, end_slot) ⇒ String
Delete a range of slots from the cluster.
-
#cluster_failover(mode = nil) ⇒ String
Force a failover of the cluster.
-
#cluster_flushslots ⇒ String
Flush all slots from the cluster.
-
#cluster_forget(node_id) ⇒ String
Remove a node from the cluster.
-
#cluster_getkeysinslot(slot, count) ⇒ Array<String>
Get keys in a specific slot.
-
#cluster_info ⇒ Hash<String, String>
Get information about the cluster.
-
#cluster_keyslot(key) ⇒ Integer
Get the slot for a key.
-
#cluster_links ⇒ Array<Hash>
Get information about cluster links.
-
#cluster_meet(ip, port) ⇒ String
Meet another node in the cluster.
-
#cluster_myid ⇒ String
Get the ID of the current node.
-
#cluster_myshardid ⇒ String
Get the shard ID of the current node.
-
#cluster_nodes ⇒ Array<Hash>
Get information about all nodes in the cluster.
-
#cluster_replicas(node_id) ⇒ Array<Hash>
Get information about replica nodes.
-
#cluster_replicate(node_id) ⇒ String
Set a node as a replica of another node.
-
#cluster_reset(hard = nil) ⇒ String
Reset the cluster.
-
#cluster_saveconfig ⇒ String
Save the cluster configuration.
-
#cluster_set_config_epoch(epoch) ⇒ String
Set the config epoch for a node.
-
#cluster_setslot(slot, state, node_id = nil) ⇒ String
Set the state of a slot.
-
#cluster_shards ⇒ Array<Hash>
Get information about cluster shards.
-
#cluster_slaves(node_id) ⇒ Array<Hash>
Get information about slave nodes (deprecated, use cluster_replicas).
-
#cluster_slots ⇒ Array<Hash>
Get information about cluster slots.
-
#readonly ⇒ String
Set the connection to read-only mode.
-
#readwrite ⇒ String
Set the connection to read-write mode.
Instance Method Details
#asking ⇒ String
Send ASKING command to the server.
13 14 15 |
# File 'lib/valkey/commands/cluster_commands.rb', line 13 def asking send_command(RequestType::ASKING) end |
#cluster_addslots(*slots) ⇒ String
Add slots to the cluster.
21 22 23 |
# File 'lib/valkey/commands/cluster_commands.rb', line 21 def cluster_addslots(*slots) send_command(RequestType::CLUSTER_ADD_SLOTS, slots) end |
#cluster_addslotsrange(start_slot, end_slot) ⇒ String
Add a range of slots to the cluster.
30 31 32 |
# File 'lib/valkey/commands/cluster_commands.rb', line 30 def cluster_addslotsrange(start_slot, end_slot) send_command(RequestType::CLUSTER_ADD_SLOTS_RANGE, [start_slot, end_slot]) end |
#cluster_bumpepoch ⇒ String
Bump the epoch of the cluster.
37 38 39 |
# File 'lib/valkey/commands/cluster_commands.rb', line 37 def cluster_bumpepoch send_command(RequestType::CLUSTER_BUMP_EPOCH) end |
#cluster_count_failure_reports(node_id) ⇒ Integer
Count failure reports for a node.
45 46 47 |
# File 'lib/valkey/commands/cluster_commands.rb', line 45 def cluster_count_failure_reports(node_id) send_command(RequestType::CLUSTER_COUNT_FAILURE_REPORTS, [node_id]) end |
#cluster_countkeysinslot(slot) ⇒ Integer
Count keys in a specific slot.
53 54 55 |
# File 'lib/valkey/commands/cluster_commands.rb', line 53 def cluster_countkeysinslot(slot) send_command(RequestType::CLUSTER_COUNT_KEYS_IN_SLOT, [slot]) end |
#cluster_delslots(*slots) ⇒ String
Delete slots from the cluster.
61 62 63 |
# File 'lib/valkey/commands/cluster_commands.rb', line 61 def cluster_delslots(*slots) send_command(RequestType::CLUSTER_DEL_SLOTS, slots) end |
#cluster_delslotsrange(start_slot, end_slot) ⇒ String
Delete a range of slots from the cluster.
70 71 72 |
# File 'lib/valkey/commands/cluster_commands.rb', line 70 def cluster_delslotsrange(start_slot, end_slot) send_command(RequestType::CLUSTER_DEL_SLOTS_RANGE, [start_slot, end_slot]) end |
#cluster_failover(mode = nil) ⇒ String
Force a failover of the cluster.
Must be sent to a replica node. Without a mode, performs a coordinated
failover (the primary is asked to pause clients and hand over). :force
promotes the replica without coordinating with the primary (useful when
the primary is unreachable); :takeover promotes it without any cluster
consensus (most aggressive — risks data loss / split brain).
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/valkey/commands/cluster_commands.rb', line 89 def cluster_failover(mode = nil) args = [] unless mode.nil? unless CLUSTER_FAILOVER_MODES.include?(mode) raise ArgumentError, "invalid CLUSTER FAILOVER mode #{mode.inspect}: expected :force or :takeover" end args << mode.to_s.upcase end send_command(RequestType::CLUSTER_FAILOVER, args) end |
#cluster_flushslots ⇒ String
Flush all slots from the cluster.
104 105 106 |
# File 'lib/valkey/commands/cluster_commands.rb', line 104 def cluster_flushslots send_command(RequestType::CLUSTER_FLUSH_SLOTS) end |
#cluster_forget(node_id) ⇒ String
Remove a node from the cluster.
112 113 114 |
# File 'lib/valkey/commands/cluster_commands.rb', line 112 def cluster_forget(node_id) send_command(RequestType::CLUSTER_FORGET, [node_id]) end |
#cluster_getkeysinslot(slot, count) ⇒ Array<String>
Get keys in a specific slot.
121 122 123 |
# File 'lib/valkey/commands/cluster_commands.rb', line 121 def cluster_getkeysinslot(slot, count) send_command(RequestType::CLUSTER_GET_KEYS_IN_SLOT, [slot, count]) end |
#cluster_info ⇒ Hash<String, String>
Get information about the cluster.
128 129 130 131 132 133 134 135 136 |
# File 'lib/valkey/commands/cluster_commands.rb', line 128 def cluster_info send_command(RequestType::CLUSTER_INFO, []) do |reply| if reply.is_a?(Hash) reply.transform_values { |v| Utils::HashifyInfo.call(v) } else Utils::HashifyInfo.call(reply) end end end |
#cluster_keyslot(key) ⇒ Integer
Get the slot for a key.
142 143 144 |
# File 'lib/valkey/commands/cluster_commands.rb', line 142 def cluster_keyslot(key) send_command(RequestType::CLUSTER_KEY_SLOT, [key]) end |
#cluster_links ⇒ Array<Hash>
Get information about cluster links.
149 150 151 |
# File 'lib/valkey/commands/cluster_commands.rb', line 149 def cluster_links send_command(RequestType::CLUSTER_LINKS, []) end |
#cluster_meet(ip, port) ⇒ String
Meet another node in the cluster.
158 159 160 |
# File 'lib/valkey/commands/cluster_commands.rb', line 158 def cluster_meet(ip, port) send_command(RequestType::CLUSTER_MEET, [ip, port]) end |
#cluster_myid ⇒ String
Get the ID of the current node.
165 166 167 |
# File 'lib/valkey/commands/cluster_commands.rb', line 165 def cluster_myid send_command(RequestType::CLUSTER_MY_ID, []) end |
#cluster_myshardid ⇒ String
Get the shard ID of the current node.
172 173 174 |
# File 'lib/valkey/commands/cluster_commands.rb', line 172 def cluster_myshardid send_command(RequestType::CLUSTER_MY_SHARD_ID, []) end |
#cluster_nodes ⇒ Array<Hash>
Get information about all nodes in the cluster.
179 180 181 182 183 184 185 186 187 |
# File 'lib/valkey/commands/cluster_commands.rb', line 179 def cluster_nodes send_command(RequestType::CLUSTER_NODES, []) do |reply| if reply.is_a?(Hash) reply.transform_values { |v| Utils::HashifyClusterNodes.call(v) } else Utils::HashifyClusterNodes.call(reply) end end end |
#cluster_replicas(node_id) ⇒ Array<Hash>
Get information about replica nodes.
193 194 195 196 197 |
# File 'lib/valkey/commands/cluster_commands.rb', line 193 def cluster_replicas(node_id) send_command(RequestType::CLUSTER_REPLICAS, [node_id]) do |reply| Utils::HashifyClusterSlaves.call(reply) end end |
#cluster_replicate(node_id) ⇒ String
Set a node as a replica of another node.
203 204 205 |
# File 'lib/valkey/commands/cluster_commands.rb', line 203 def cluster_replicate(node_id) send_command(RequestType::CLUSTER_REPLICATE, [node_id]) end |
#cluster_reset(hard = nil) ⇒ String
Reset the cluster.
211 212 213 214 215 |
# File 'lib/valkey/commands/cluster_commands.rb', line 211 def cluster_reset(hard = nil) args = [] args << "HARD" if hard send_command(RequestType::CLUSTER_RESET, args) end |
#cluster_saveconfig ⇒ String
Save the cluster configuration.
220 221 222 |
# File 'lib/valkey/commands/cluster_commands.rb', line 220 def cluster_saveconfig send_command(RequestType::CLUSTER_SAVE_CONFIG) end |
#cluster_set_config_epoch(epoch) ⇒ String
Set the config epoch for a node.
228 229 230 |
# File 'lib/valkey/commands/cluster_commands.rb', line 228 def cluster_set_config_epoch(epoch) send_command(RequestType::CLUSTER_SET_CONFIG_EPOCH, [epoch]) end |
#cluster_setslot(slot, state, node_id = nil) ⇒ String
Set the state of a slot.
238 239 240 241 242 |
# File 'lib/valkey/commands/cluster_commands.rb', line 238 def cluster_setslot(slot, state, node_id = nil) args = [slot, state] args << node_id if node_id send_command(RequestType::CLUSTER_SETSLOT, args) end |
#cluster_shards ⇒ Array<Hash>
Get information about cluster shards.
247 248 249 |
# File 'lib/valkey/commands/cluster_commands.rb', line 247 def cluster_shards send_command(RequestType::CLUSTER_SHARDS, []) end |
#cluster_slaves(node_id) ⇒ Array<Hash>
Get information about slave nodes (deprecated, use cluster_replicas).
254 255 256 257 258 |
# File 'lib/valkey/commands/cluster_commands.rb', line 254 def cluster_slaves(node_id) send_command(RequestType::CLUSTER_SLAVES, [node_id]) do |reply| Utils::HashifyClusterSlaves.call(reply) end end |
#cluster_slots ⇒ Array<Hash>
Get information about cluster slots.
263 264 265 266 267 |
# File 'lib/valkey/commands/cluster_commands.rb', line 263 def cluster_slots send_command(RequestType::CLUSTER_SLOTS) do |reply| Utils::HashifyClusterSlots.call(reply) end end |
#readonly ⇒ String
Set the connection to read-only mode.
272 273 274 |
# File 'lib/valkey/commands/cluster_commands.rb', line 272 def readonly send_command(RequestType::READ_ONLY) end |
#readwrite ⇒ String
Set the connection to read-write mode.
279 280 281 |
# File 'lib/valkey/commands/cluster_commands.rb', line 279 def readwrite send_command(RequestType::READ_WRITE) end |