Class: Herdis::Client::ReDistributed

Inherits:
Redis::Distributed
  • Object
show all
Defined in:
lib/herdis/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(urls, options = {}) ⇒ ReDistributed

Returns a new instance of ReDistributed.



24
25
26
27
28
29
# File 'lib/herdis/client.rb', line 24

def initialize(urls, options = {})
  @tag = options.delete(:tag) || /^\{(.+?)\}/
  @default_options = options
  @nodes = urls.map { |url| Redis.connect(options.merge(:url => url)) }
  @subscribed_node = nil
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



22
23
24
# File 'lib/herdis/client.rb', line 22

def nodes
  @nodes
end

Instance Method Details

#add_node(url) ⇒ Object



35
36
37
# File 'lib/herdis/client.rb', line 35

def add_node(url)
  raise "You can't add nodes to #{self}!"
end

#node_for(key) ⇒ Object



31
32
33
# File 'lib/herdis/client.rb', line 31

def node_for(key)
  @nodes[Digest::SHA1.hexdigest(key_tag(key.to_s) || key.to_s).to_i(16) % @nodes.size]
end