Following the example
in http://sequel.jeremyevans.net/rdoc/files/doc/sharding_rdoc.html does not
seem to work for me.
First:
DB=Sequel.connect('postgres://master_server/database', :servers=>{:
read_only=>proc{|db| {:host=>db.get_slave_host}}})
def DB.get_slave_host
@current_host ||= -1
"slave_server#{(@current_host+=1)%4}"
end
Results in a 'method not defined' error (this is in Ruby 2.1.3). I have
changed my code to define the method inside the proc:
DB=Sequel.connect('postgres://master_server/database', :servers=>{:
read_only=>proc{ |db|
unless db.respond_to?(:get_slave_host)
def db.get_slave_host
@current_host ||= -1
"slave_server#{(@current_host+=1)%4}"
end
end
{:host=>db.get_slave_host}}})
But the method only appears to be called twice: Once at load time and once
for the first query.
After that, the last return value is used, which does not result in a round
robin selection of the DB servers.
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.