Class: Redis::DistributedStore

Inherits:
Distributed
  • Object
show all
Defined in:
lib/redis/distributed_store.rb

Constant Summary collapse

@@timeout =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(addresses, options = {}) ⇒ DistributedStore

Returns a new instance of DistributedStore.



8
9
10
11
12
13
14
15
# File 'lib/redis/distributed_store.rb', line 8

def initialize(addresses, options = {})
  _extend_namespace options
  @ring = options[:ring] || Redis::HashRing.new([], options[:replicas] || Redis::HashRing::POINTS_PER_SERVER)

  addresses.each do |address|
    @ring.add_node(::Redis::Store.new _merge_options(address, options))
  end
end

Instance Attribute Details

#ringObject (readonly)

Returns the value of attribute ring.



6
7
8
# File 'lib/redis/distributed_store.rb', line 6

def ring
  @ring
end

Instance Method Details

#get(key, options = nil) ⇒ Object



29
30
31
# File 'lib/redis/distributed_store.rb', line 29

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

#nodesObject



17
18
19
# File 'lib/redis/distributed_store.rb', line 17

def nodes
  ring.nodes
end

#reconnectObject



21
22
23
# File 'lib/redis/distributed_store.rb', line 21

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

#redis_versionObject



37
38
39
# File 'lib/redis/distributed_store.rb', line 37

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

#set(key, value, options = nil) ⇒ Object



25
26
27
# File 'lib/redis/distributed_store.rb', line 25

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

#setex(key, expiry, value, options = nil) ⇒ Object



49
50
51
# File 'lib/redis/distributed_store.rb', line 49

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

#setnx(key, value, options = nil) ⇒ Object



33
34
35
# File 'lib/redis/distributed_store.rb', line 33

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

#supports_redis_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/redis/distributed_store.rb', line 41

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