For those of you who might have seen my other blog, my goal is to convey the fact that using Couchbase with any of the language client libraries is very straightforward. The client libraries handle the complexity of the connection and the inherent distributed nature of the cluster. Here’s the Hello World code in Ruby.
require ‘couchbase’
client = Couchbase.new “http://127.0.0.1:8091/pools/default, :quiet=> false”
client.quiet = false
begin
spoon = client.get “spoon”
puts spoon
rescue Couchbase::Error::NotFound => e
puts “There is no spoon.”
client.set “spoon”, “Hello World!”, :ttl => 10
end
A Ruby program to store the data would look something like below. We use the key “_id” in the document to store the details of all the beers on the world in Couchbase. A very simple program that parses the file and stores each entry based on the key.
require ‘couchbase’
require ‘yajl’couchbase = Couchbase.new(‘http://127.0.0.1:8091/pools/default’)
beers = Yajl::Parser.parse(File.read(‘beerdb’))
beers.each do |beer|
couchbase.set(beer[‘_id’], beer)
end
I have gone way beyond a simple Hello World. I will be contributing more towards using Ruby Client libraries and Couchbase, but, in the meantime here are some useful links.
[…] Zablocki introduces the new .NET SDK, while Rags Srinivas covers the updates in both the Java and Ruby SDKs. Our own Jan Lehnardt also gives a quick rundown on the PHP SDK. PHP and Ruby get their […]