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 = "[email protected]"
+ 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 ==

Reply via email to