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.



117
118
119
# File 'lib/redis_client/cluster/command.rb', line 117

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

Class Method Details

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

rubocop:disable Metrics/AbcSize



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/redis_client/cluster/command.rb', line 65

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)


125
126
127
# File 'lib/redis_client/cluster/command.rb', line 125

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

#get_spec(name) ⇒ Object



121
122
123
# File 'lib/redis_client/cluster/command.rb', line 121

def get_spec(name)
  @commands[name] || @commands[name.to_s.downcase(:ascii)]
end