]>
git.saurik.com Git - redis.git/blob - client-libraries/ruby/lib/dist_redis.rb
5 def initialize(*servers
)
8 server
, port
= s
.split(':')
9 srvs
<< Redis
.new(:host => server
, :port => port
)
11 @ring = HashRing
.new srvs
21 def add_server(server
)
22 server
, port
= server
.split(':')
23 @ring.add_node Redis
.new(:host => server
, :port => port
)
26 def method_missing(sym
, *args
, &blk
)
27 if redis
= node_for_key(args
.first
.to_s
)
28 redis
.send sym
, *args
, &blk
36 @ring.nodes
.each
do |red
|
37 keyz
.concat red
.keys(glob
)
43 @ring.nodes
.each
do |red
|
49 @ring.nodes
.each
do |red
|
55 @ring.nodes
.each
do |red
|
61 @ring.nodes
.each
do |red
|
62 red
.keys("*").each
do |key
|
73 r
= DistRedis
.new
'localhost:6379', 'localhost:6380', 'localhost:6381', 'localhost:6382'
76 r
['urmom1'] = 'urmom1'
77 r
['urdad1'] = 'urdad1'
78 r
['urmom2'] = 'urmom2'
79 r
['urdad2'] = 'urdad2'
80 r
['urmom3'] = 'urmom3'
81 r
['urdad3'] = 'urdad3'
91 r
.push_tail
'listor', 'foo1'
92 r
.push_tail
'listor', 'foo2'
93 r
.push_tail
'listor', 'foo3'
94 r
.push_tail
'listor', 'foo4'
95 r
.push_tail
'listor', 'foo5'
97 p r
.pop_tail('listor')
98 p r
.pop_tail('listor')
99 p r
.pop_tail('listor')
100 p r
.pop_tail('listor')
101 p r
.pop_tail('listor')
103 puts
"key distribution:"
105 r
.ring
.nodes
.each
do |red
|
106 p
[red
.port
, red
.keys("*")]