Sha256: 6e477bb86c49053aad5b5fa68c385b8d545f2f38c4b7b5edfd94fdeb02e7c746

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

require 'redis/distributed'

class Redis
  class DistributedStore < Distributed
    @@timeout = 5
    attr_reader :ring

    def initialize(addresses, options = { })
      nodes = addresses.map do |address|
        ::Redis::Store.new _merge_options(address, options)
      end

      _extend_namespace options
      @ring = Redis::HashRing.new nodes
    end

    def nodes
      ring.nodes
    end

    def reconnect
      nodes.each {|node| node.reconnect }
    end

    def set(key, value, options = nil)
      node_for(key).set(key, value, options)
    end

    def get(key, options = nil)
      node_for(key).get(key, options)
    end

    def setnx(key, value, options = nil)
      node_for(key).setnx(key, value, options)
    end

    def redis_version
      nodes.first.redis_version unless nodes.empty?
    end

    def supports_redis_version?(version)
      if nodes.empty?
        false
      else
        nodes.first.supports_redis_version?(version)
      end
    end

    def setex(key, expiry, value, options = nil)
      node_for(key).setex(key, expiry, value, options)
    end

    private
      def _extend_namespace(options)
        @namespace = options[:namespace]
        extend ::Redis::Store::Namespace if @namespace
      end

      def _merge_options(address, options)
        address.merge({
          :timeout => options[:timeout] || @@timeout, 
          :namespace => options[:namespace]
        })
      end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
redis-store-1.4.1 lib/redis/distributed_store.rb
redis-store-1.4.0 lib/redis/distributed_store.rb
redis-store-1.3.0 lib/redis/distributed_store.rb
redis-store-1.2.0 lib/redis/distributed_store.rb
redis-store-1.2.0.pre lib/redis/distributed_store.rb