public
Created

  • Download Gist
cb_connect.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
require 'rubygems'
require 'couchbase'
CONFIG = {
:node_list => ["localhost:8091"],
:key_prefix => "pool_",
:pool_size => 3
}
 
def connection(bucket)
@servers ||= {}
@servers[bucket] ||= begin
size = CONFIG[:pool_size]
params = CONFIG.merge(:bucket => bucket)
Couchbase::ConnectionPool.new(size, params)
end
end
 
connection("bucket1").set('foo', 'bar')
connection("bucket2").set('bar', 'foo')
threads = []
5.times do
threads << Thread.new do
connection("bucket1").get('foo')
connection("bucket2").get('bar')
end
end
threads.map do |t|
puts [t.object_id, t.value].join("\t")
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.