Class: RedisClient::Cluster::Command
- Inherits:
-
Object
- Object
- RedisClient::Cluster::Command
- Defined in:
- lib/redis_client/cluster/command.rb
Defined Under Namespace
Classes: Detail
Class Method Summary collapse
-
.load(nodes, slow_command_timeout: -1)) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Summary collapse
- #exists?(name) ⇒ Boolean
- #extract_first_key(command) ⇒ Object
-
#initialize(commands) ⇒ Command
constructor
A new instance of Command.
- #should_send_to_primary?(command) ⇒ Boolean
- #should_send_to_replica?(command) ⇒ Boolean
Constructor Details
#initialize(commands) ⇒ Command
Returns a new instance of Command.
77 78 79 |
# File 'lib/redis_client/cluster/command.rb', line 77 def initialize(commands) @commands = commands || EMPTY_HASH end |
Class Method Details
.load(nodes, slow_command_timeout: -1)) ⇒ Object
rubocop:disable Metrics/AbcSize
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/redis_client/cluster/command.rb', line 26 def load(nodes, slow_command_timeout: -1) # rubocop:disable Metrics/AbcSize cmd = errors = nil nodes&.each do |node| regular_timeout = node.read_timeout node.read_timeout = slow_command_timeout > 0.0 ? slow_command_timeout : regular_timeout reply = node.call('command') node.read_timeout = regular_timeout commands = parse_command_reply(reply) cmd = ::RedisClient::Cluster::Command.new(commands) break rescue ::RedisClient::Error => e errors ||= [] errors << e end return cmd unless cmd.nil? raise ::RedisClient::Cluster::InitialSetupError.from_errors(errors) end |
Instance Method Details
#exists?(name) ⇒ Boolean
96 97 98 |
# File 'lib/redis_client/cluster/command.rb', line 96 def exists?(name) @commands.key?(name) || @commands.key?(name.to_s.downcase(:ascii)) end |
#extract_first_key(command) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/redis_client/cluster/command.rb', line 81 def extract_first_key(command) i = determine_first_key_position(command) return EMPTY_STRING if i == 0 command[i] end |
#should_send_to_primary?(command) ⇒ Boolean
88 89 90 |
# File 'lib/redis_client/cluster/command.rb', line 88 def should_send_to_primary?(command) find_command_info(command.first)&.write? end |
#should_send_to_replica?(command) ⇒ Boolean
92 93 94 |
# File 'lib/redis_client/cluster/command.rb', line 92 def should_send_to_replica?(command) find_command_info(command.first)&.readonly? end |