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
16
17
# File 'lib/redis/distributed_store.rb', line 8

def initialize(addresses, options = {})
  _extend_namespace options
  # `@tag` introduced in `redis-rb` 5.0
  @tag = options[:tag] || /^\{(.+?)\}/
  @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



31
32
33
# File 'lib/redis/distributed_store.rb', line 31

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

#nodesObject



19
20
21
# File 'lib/redis/distributed_store.rb', line 19

def nodes
  ring.nodes
end

#reconnectObject



23
24
25
# File 'lib/redis/distributed_store.rb', line 23

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

#redis_versionObject



39
40
41
# File 'lib/redis/distributed_store.rb', line 39

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

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



27
28
29
# File 'lib/redis/distributed_store.rb', line 27

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

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



51
52
53
# File 'lib/redis/distributed_store.rb', line 51

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

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



35
36
37
# File 'lib/redis/distributed_store.rb', line 35

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

#supports_redis_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


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

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