Class: TokyoTyrant::Balancer::Base

Inherits:
Object
  • Object
show all
Defined in:
ext/tokyo_tyrant/balancer.rb

Direct Known Subclasses

DB, Table

Instance Method Summary collapse

Constructor Details

#initialize(servers = []) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
11
12
13
# File 'ext/tokyo_tyrant/balancer.rb', line 6

def initialize(servers = [])
  servers.collect! do |server|
    host, port = server.split(':')
    klass.new(host, port.to_i)
  end
  @servers = servers
  @ring = TokyoTyrant::ConstistentHash.new(servers)
end

Instance Method Details

#add_double(key, i = 1.0) ⇒ Object Also known as: adddouble



46
47
48
49
# File 'ext/tokyo_tyrant/balancer.rb', line 46

def add_double(key, i = 1.0)
  db = db_for_key(key)
  db.add_double(key, i)
end

#add_int(key, i = 1) ⇒ Object Also known as: addint, increment



34
35
36
37
# File 'ext/tokyo_tyrant/balancer.rb', line 34

def add_int(key, i = 1)
  db = db_for_key(key)
  db.add_int(key, i)
end

#check(key) ⇒ Object Also known as: has_key?, key?, include?, member?



128
129
130
# File 'ext/tokyo_tyrant/balancer.rb', line 128

def check(key)
  @servers.any?{ |server| server.check(key) }
end

#closeObject

Aggregate Methods



100
101
102
# File 'ext/tokyo_tyrant/balancer.rb', line 100

def close
  @servers.all?{ |server| server.close }
end

#db_for_key(key) ⇒ Object



23
24
25
# File 'ext/tokyo_tyrant/balancer.rb', line 23

def db_for_key(key)
  ring.db_for_key(key)
end

#delete_keys_with_prefix(prefix, max = -1)) ⇒ Object Also known as: dfwmkeys



144
145
146
147
# File 'ext/tokyo_tyrant/balancer.rb', line 144

def delete_keys_with_prefix(prefix, max = -1)
  @servers.each{ |server| server.delete_keys_with_prefix(prefix, max) }
  nil
end

#empty?Boolean

Returns:

  • (Boolean)


111
112
113
# File 'ext/tokyo_tyrant/balancer.rb', line 111

def empty?
  @servers.all?{ |server| server.empty? }
end

#fetch(key, &block) ⇒ Object



88
89
90
91
# File 'ext/tokyo_tyrant/balancer.rb', line 88

def fetch(key, &block)
  db = db_for_key(key)
  db.fetch(key, &block)
end

#fwmkeys(prefix, max = -1)) ⇒ Object



140
141
142
# File 'ext/tokyo_tyrant/balancer.rb', line 140

def fwmkeys(prefix, max = -1)
  @servers.collect{ |server| server.fwmkeys(prefix, max) }.flatten
end

#get(key) ⇒ Object Also known as: []

Delegate Methods



28
29
30
31
# File 'ext/tokyo_tyrant/balancer.rb', line 28

def get(key)
  db = db_for_key(key)
  db.get(key)
end

#get_double(key) ⇒ Object



52
53
54
55
# File 'ext/tokyo_tyrant/balancer.rb', line 52

def get_double(key)
  db = db_for_key(key)
  db.get_double(key)
end

#get_int(key) ⇒ Object



41
42
43
44
# File 'ext/tokyo_tyrant/balancer.rb', line 41

def get_int(key)
  db = db_for_key(key)
  db.get_int(key)
end

#keysObject



150
151
152
# File 'ext/tokyo_tyrant/balancer.rb', line 150

def keys
  @servers.collect{ |server| server.keys }.flatten.uniq
end

#optimize(*args) ⇒ Object



124
125
126
# File 'ext/tokyo_tyrant/balancer.rb', line 124

def optimize(*args)
  @servers.all?{ |server| server.optimize(*args) }
end

#out(key) ⇒ Object Also known as: delete



93
94
95
96
# File 'ext/tokyo_tyrant/balancer.rb', line 93

def out(key)
  db = db_for_key(key)
  db.out(key)
end

#put(key, value) ⇒ Object Also known as: []=



57
58
59
60
# File 'ext/tokyo_tyrant/balancer.rb', line 57

def put(key, value)
  db = db_for_key(key)
  db.put(key, value)
end

#putcat(key, value) ⇒ Object



68
69
70
71
# File 'ext/tokyo_tyrant/balancer.rb', line 68

def putcat(key, value)
  db = db_for_key(key)
  db.putcat(key, value)
end

#putkeep(key, value) ⇒ Object



63
64
65
66
# File 'ext/tokyo_tyrant/balancer.rb', line 63

def putkeep(key, value)
  db = db_for_key(key)
  db.putkeep(key, value)
end

#putnr(key, value) ⇒ Object



78
79
80
81
# File 'ext/tokyo_tyrant/balancer.rb', line 78

def putnr(key, value)
  db = db_for_key(key)
  db.putnr(key, value)
end

#putshl(key, value, width) ⇒ Object



73
74
75
76
# File 'ext/tokyo_tyrant/balancer.rb', line 73

def putshl(key, value, width)
  db = db_for_key(key)
  db.putshl(key, value, width)
end

#ringObject



15
16
17
# File 'ext/tokyo_tyrant/balancer.rb', line 15

def ring
  @ring
end

#rnumObject Also known as: count, size, length



104
105
106
# File 'ext/tokyo_tyrant/balancer.rb', line 104

def rnum
  @servers.collect{ |server| server.rnum }.inject(nil){ |sum,x| sum ? sum+x : x }
end

#serversObject



19
20
21
# File 'ext/tokyo_tyrant/balancer.rb', line 19

def servers
  @servers
end

#set_index(name, type) ⇒ Object



136
137
138
# File 'ext/tokyo_tyrant/balancer.rb', line 136

def set_index(name, type)
  @servers.all?{ |server| server.set_index(name, type) }
end

#syncObject



120
121
122
# File 'ext/tokyo_tyrant/balancer.rb', line 120

def sync
  @servers.each{ |server| server.sync }
end

#valuesObject



154
155
156
# File 'ext/tokyo_tyrant/balancer.rb', line 154

def values
  @servers.collect{ |server| server.values }.flatten.uniq
end

#vanishObject Also known as: clear



115
116
117
# File 'ext/tokyo_tyrant/balancer.rb', line 115

def vanish
  @servers.all?{ |server| server.vanish }
end

#vsiz(key) ⇒ Object



83
84
85
86
# File 'ext/tokyo_tyrant/balancer.rb', line 83

def vsiz(key)
  db = db_for_key(key)
  db.vsiz(key)
end