cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Cassandra Wiki] Update of "ClientExamples" by Pablo Delgado
Date Mon, 23 Nov 2009 00:01:01 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Cassandra Wiki" for change notification.

The "ClientExamples" page has been changed by Pablo Delgado.
http://wiki.apache.org/cassandra/ClientExamples?action=diff&rev1=35&rev2=36

--------------------------------------------------

          tr.close();
      }
  }
+ }}}
+ 
+ == Ruby ==
+ 
+ Install the Thrift gem that will take advantage of the native libraries (previously installed.
Reference [[http://chrischandler.name/ruby/using-cassandras-thrift-interface-with-ruby/|Using
Cassandra's Thrift Interface with Ruby]])
+ 
+ `shell> sudo gem install thrift`
+ 
+ Navigate to your Cassandra install’s interface directory (cassandra/interface) and build
the ruby code:
+ 
+ `shell> thrift --gen rb:new_style cassandra.thrift`
+ 
+ {{{
+ #!/usr/bin/env ruby
+ require './cassandra'
+ require './cassandra_constants'
+ require './cassandra_types'
+ require 'pp'
+ 
+ transport = Thrift::BufferedTransport.new(Thrift::Socket.new("localhost", "9160"))
+ transport.open
+ 
+ client = CassandraThrift::Cassandra::Client.new(Thrift::BinaryProtocol.new(transport))
+ 
+ keyspace = "Keyspace1"
+ key = "dude_login"
+ columnPath = CassandraThrift::ColumnPath.new(:column_family => "Standard1", :column =>
"email")
+ value = "dude@example.com"
+ t = Time.now
+ timestamp = t.to_i * 1_000_000 + t.usec
+ 
+ client.insert(keyspace, key ,columnPath, value, timestamp, CassandraThrift::ConsistencyLevel::ZERO)
+ 
+ begin
+   pp client.get(keyspace, key, columnPath, CassandraThrift::ConsistencyLevel::ONE)
+ rescue CassandraThrift::NotFoundException => e
+   puts "Key not found."
+ end
  }}}
  
  == Python ==

Mime
View raw message