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 16 17 |
# File 'lib/redis/distributed_store.rb', line 8 def initialize(addresses, = {}) _extend_namespace # `@tag` introduced in `redis-rb` 5.0 @tag = [:tag] || /^\{(.+?)\}/ @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
31 32 33 |
# File 'lib/redis/distributed_store.rb', line 31 def get(key, = nil) node_for(key).get(key, ) end |
#nodes ⇒ Object
19 20 21 |
# File 'lib/redis/distributed_store.rb', line 19 def nodes ring.nodes end |
#reconnect ⇒ Object
23 24 25 |
# File 'lib/redis/distributed_store.rb', line 23 def reconnect nodes.each { |node| node.reconnect } end |
#redis_version ⇒ Object
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, = nil) node_for(key).set(key, value, ) end |
#setex(key, expiry, value, options = nil) ⇒ Object
51 52 53 |
# File 'lib/redis/distributed_store.rb', line 51 def setex(key, expiry, value, = nil) node_for(key).setex(key, expiry, value, ) end |
#setnx(key, value, options = nil) ⇒ Object
35 36 37 |
# File 'lib/redis/distributed_store.rb', line 35 def setnx(key, value, = nil) node_for(key).setnx(key, value, ) end |
#supports_redis_version?(version) ⇒ 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 |