Class: Redic::Cluster
- Inherits:
-
Object
- Object
- Redic::Cluster
- Defined in:
- lib/redic/cluster.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #commit ⇒ Object
-
#initialize(url = "redis://localhost:12001", timeout = 10_000_000) ⇒ Cluster
constructor
A new instance of Cluster.
- #queue(*args) ⇒ Object
Constructor Details
#initialize(url = "redis://localhost:12001", timeout = 10_000_000) ⇒ Cluster
Returns a new instance of Cluster.
8 9 10 11 12 |
# File 'lib/redic/cluster.rb', line 8 def initialize(url="redis://localhost:12001", timeout=10_000_000) @url = url @node = Redic.new(url, timeout) @debug = false end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
6 7 8 |
# File 'lib/redic/cluster.rb', line 6 def debug @debug end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
5 6 7 |
# File 'lib/redic/cluster.rb', line 5 def node @node end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/redic/cluster.rb', line 4 def url @url end |
Instance Method Details
#call(*args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/redic/cluster.rb', line 14 def call(*args) res = @node.call(*args) return res unless res.is_a?(RuntimeError) parts = res..split if parts.first == "MOVED" slot, addr = parts[1,2] $stderr.puts "-> Redirected to slot [#{slot}] located at #{addr}" if @debug @node.call("QUIT") @node = Redic.new("redis://#{addr}", @node.timeout) call(*args) else res end end |
#commit ⇒ Object
40 41 42 |
# File 'lib/redic/cluster.rb', line 40 def commit @node.commit end |
#queue(*args) ⇒ Object
36 37 38 |
# File 'lib/redic/cluster.rb', line 36 def queue(*args) @node.queue(*args) end |