Sha256: 21221f7edf87c038e0abc7acf5b76d0f52acb2ba9b55cc2b3c0be91172d1b834

Contents?: true

Size: 924 Bytes

Versions: 4

Compression:

Stored size: 924 Bytes

Contents

module RedisCluster

  class Node
    # slots is a range array: [1..100, 300..500]
    attr_accessor :slots

    #
    # basic requires:
    #   {host: xxx.xxx.xx.xx, port: xxx}
    # redis cluster don't support select db, use default 0
    #
    def initialize(opts)
      @options = opts
      @slots = []
    end

    def name
      "#{@options[:host]}:#{@options[:port]}"
    end

    def host_hash
      {host: @options[:host], port: @options[:port]}
    end

    def has_slot?(slot)
      slots.any? {|range| range.include? slot }
    end

    def asking
      execute(:asking)
    end

    def execute(method, args)
      connection.public_send(method, *args)
    end

    def connection
      @connection ||= self.class.redis(@options)
    end

    def self.redis(options)
      extra_options = {timeout: Configuration::DEFAULT_TIMEOUT}
      ::Redis.new(options.merge(extra_options))
    end

  end # end Node

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
redis_cluster-0.2.3 lib/redis_cluster/node.rb
redis_cluster-0.2.1 lib/redis_cluster/node.rb
redis_cluster-0.2.0 lib/redis_cluster/node.rb
redis_cluster-0.1.9 lib/redis_cluster/node.rb