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.
client = Couchbase.new “http://127.0.0.1:8091/pools/default, :quiet=> false”
client.quiet = false
spoon = client.get “spoon”
rescue Couchbase::Error::NotFound => e
puts “There is no spoon.”
client.set “spoon”, “Hello World!”, :ttl => 10
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 ‘yajl’couchbase = Couchbase.new(‘http://127.0.0.1:8091/pools/default’)
beers = Yajl::Parser.parse(File.read(‘beerdb’))
beers.each do |beer|
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.