Class: Redis::DistributedStore
- Inherits:
-
Distributed
- Object
- Distributed
- Redis::DistributedStore
- Defined in:
- lib/redis/distributed_store.rb
Constant Summary collapse
- @@timeout =
5
Instance Attribute Summary collapse
-
#ring ⇒ Object
readonly
Returns the value of attribute ring.
Instance Method Summary collapse
- #get(key, options = nil) ⇒ Object
-
#initialize(addresses, options = {}) ⇒ DistributedStore
constructor
A new instance of DistributedStore.
- #nodes ⇒ Object
- #reconnect ⇒ Object
- #redis_version ⇒ Object
- #set(key, value, options = nil) ⇒ Object
- #setex(key, expiry, value, options = nil) ⇒ Object
- #setnx(key, value, options = nil) ⇒ Object
- #supports_redis_version?(version) ⇒ Boolean
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, = {}) _extend_namespace @ring = [:ring] || Redis::HashRing.new([], [:replicas] || Redis::HashRing::POINTS_PER_SERVER) addresses.each do |address| @ring.add_node(::Redis::Store.new (address, )) end end |
Instance Attribute Details
#ring ⇒ Object (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, = nil) node_for(key).get(key, ) end |
#nodes ⇒ Object
17 18 19 |
# File 'lib/redis/distributed_store.rb', line 17 def nodes ring.nodes end |
#reconnect ⇒ Object
21 22 23 |
# File 'lib/redis/distributed_store.rb', line 21 def reconnect nodes.each { |node| node.reconnect } end |
#redis_version ⇒ Object
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, = nil) node_for(key).set(key, value, ) end |
#setex(key, expiry, value, options = nil) ⇒ Object
49 50 51 |
# File 'lib/redis/distributed_store.rb', line 49 def setex(key, expiry, value, = nil) node_for(key).setex(key, expiry, value, ) end |
#setnx(key, value, options = nil) ⇒ Object
33 34 35 |
# File 'lib/redis/distributed_store.rb', line 33 def setnx(key, value, = nil) node_for(key).setnx(key, value, ) end |
#supports_redis_version?(version) ⇒ 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 |