Class: RedisClient::Cluster::Command
- Inherits:
-
Object
- Object
- RedisClient::Cluster::Command
- Defined in:
- lib/redis_client/cluster/command.rb
Defined Under Namespace
Classes: Detail
Constant Summary collapse
- EMPTY_STRING =
''- LEFT_BRACKET =
'{'- RIGHT_BRACKET =
'}'- EMPTY_HASH =
{}.freeze
Class Method Summary collapse
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.
60 61 62 |
# File 'lib/redis_client/cluster/command.rb', line 60 def initialize(commands) @commands = commands || EMPTY_HASH end |
Class Method Details
.load(nodes, slow_command_timeout: -1)) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/redis_client/cluster/command.rb', line 24 def load(nodes, slow_command_timeout: -1) 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, errors end |
Instance Method Details
#exists?(name) ⇒ Boolean
83 84 85 |
# File 'lib/redis_client/cluster/command.rb', line 83 def exists?(name) @commands.key?(::RedisClient::Cluster::NormalizedCmdName.instance.get_by_name(name)) end |
#extract_first_key(command) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/redis_client/cluster/command.rb', line 64 def extract_first_key(command) i = determine_first_key_position(command) return EMPTY_STRING if i == 0 key = (command[i].is_a?(Array) ? command[i].flatten.first : command[i]).to_s hash_tag = extract_hash_tag(key) hash_tag.empty? ? key : hash_tag end |
#should_send_to_primary?(command) ⇒ Boolean
73 74 75 76 |
# File 'lib/redis_client/cluster/command.rb', line 73 def should_send_to_primary?(command) name = ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_command(command) @commands[name]&.write? end |
#should_send_to_replica?(command) ⇒ Boolean
78 79 80 81 |
# File 'lib/redis_client/cluster/command.rb', line 78 def should_send_to_replica?(command) name = ::RedisClient::Cluster::NormalizedCmdName.instance.get_by_command(command) @commands[name]&.readonly? end |