RubyではじめてのCassandra

まずはそれらしいGemをインストール。
http://github.com/fauna/cassandra

% gem i cassandra
% gem li

*** LOCAL GEMS ***

cassandra (0.8.2)
json (1.4.3)
rake (0.8.7)
rdoc (2.5.8)
rubygems-update (1.3.7)
simple_uuid (0.1.1)
thrift (0.2.0.3)
thrift_client (0.4.3)

あとはREADMEを見ながらしなっとね。

% irb          
ruby-1.9.1-p378 > require 'cassandra'
 => true 
ruby-1.9.1-p378 > client = Cassandra.new('Keyspace1', '127.0.0.1:9160')
 => #<Cassandra:76402046, @keyspace="Keyspace1", @schema={}, @servers=["127.0.0.1:9160"]> 
ruby-1.9.1-p378 > p client.keyspaces
["Keyspace1", "system"]
 => ["Keyspace1", "system"] 
ruby-1.9.1-p378 > client.get(:Standard1, 'hoge')
 => {"bar"=>"Y", "foo"=>"X"} 
ruby-1.9.1-p378 > client.insert(:Standard1, 'hoge', {'foo' => 'x', 'bar' => 'y', 'baz' => 'z'})
 => nil 
ruby-1.9.1-p378 > client.get(:Standard1, 'hoge')
 => {"bar"=>"y", "baz"=>"z", "foo"=>"x"} 
ruby-1.9.1-p378 > client.remove(:Standard1, 'hoge')
 => nil 
ruby-1.9.1-p378 > client.get(:Standard1, 'hoge')
 => {} 
ruby-1.9.1-p378 > exit

おいおいThriftも調べねばだなー。