Class: RedisClient::Cluster::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_client/cluster/command.rb

Defined Under Namespace

Classes: Detail

Class Method Summary collapse

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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