Skip to content

Instantly share code, notes, and snippets.

@rbin
Created August 7, 2013 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbin/6172557 to your computer and use it in GitHub Desktop.
Save rbin/6172557 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment