class RedisCluster::Node

Attributes

options[RW]
slots[RW]

slots is a range array: [1..100, 300..500]

Public Class Methods

new(opts) click to toggle source

basic requires:

{host: xxx.xxx.xx.xx, port: xxx}

redis cluster don't support select db, use default 0

# File lib/redis_cluster/node.rb, line 14
def initialize(opts)
  @options = opts
  @slots = []
end
redis(options) click to toggle source
# File lib/redis_cluster/node.rb, line 43
def self.redis(options)
  default_options = {timeout: Configuration::DEFAULT_TIMEOUT, driver: 'hiredis'.freeze}
  ::Redis.new(default_options.merge(options))
end

Public Instance Methods

asking() click to toggle source
# File lib/redis_cluster/node.rb, line 31
def asking
  execute(:asking)
end
connection() click to toggle source
# File lib/redis_cluster/node.rb, line 39
def connection
  @connection ||= self.class.redis(options)
end
execute(method, args, &block) click to toggle source
# File lib/redis_cluster/node.rb, line 35
def execute(method, args, &block)
  connection.public_send(method, *args, &block)
end
has_slot?(slot) click to toggle source
# File lib/redis_cluster/node.rb, line 27
def has_slot?(slot)
  slots.any? {|range| range.include? slot }
end
host_hash() click to toggle source
# File lib/redis_cluster/node.rb, line 23
def host_hash
  {host: @options[:host], port: @options[:port]}
end
name() click to toggle source
# File lib/redis_cluster/node.rb, line 19
def name
  "#{@options[:host]}:#{@options[:port]}"
end