Class: RedisClient::Cluster::Command

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

Defined Under Namespace

Classes: Spec

Constant Summary collapse

EMPTY_STRING =
''

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(commands) ⇒ Command

Returns a new instance of Command.



172
173
174
# File 'lib/redis_client/cluster/command.rb', line 172

def initialize(commands)
  @commands = commands || EMPTY_HASH
end

Class Method Details

.load(nodes, slow_command_timeout: -1)) ⇒ Object

rubocop:disable Metrics/AbcSize



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/redis_client/cluster/command.rb', line 75

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')
    commands = parse_command_reply(reply)
    cmd = ::RedisClient::Cluster::Command.new(commands)
    break
  rescue ::RedisClient::Error => e
    errors ||= []
    errors << e
  ensure
    node.read_timeout = regular_timeout
  end

  return cmd unless cmd.nil?

  raise ::RedisClient::Cluster::InitialSetupError.from_errors(errors)
end

Instance Method Details

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/redis_client/cluster/command.rb', line 187

def exists?(name)
  @commands.key?(name) || @commands.key?(name.to_s.downcase(:ascii))
end

#get_spec(command) ⇒ Object

rubocop:disable Metrics/AbcSize



176
177
178
179
180
181
182
183
184
185
# File 'lib/redis_client/cluster/command.rb', line 176

def get_spec(command) # rubocop:disable Metrics/AbcSize
  name = command.first
  spec = @commands[name] || @commands[name.to_s.downcase(:ascii)]
  return spec if spec.nil? || spec.subcommands.nil?

  subcommand = command[1]
  return spec if subcommand.nil?

  spec.subcommands[subcommand] || spec.subcommands[subcommand.to_s.downcase(:ascii)] || spec
end