You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by Apache Wiki <wi...@apache.org> on 2010/02/05 15:35:51 UTC
[Cassandra Wiki] Update of "ClientExamples" by JonathanEllis
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 JonathanEllis.
The comment on this change is: r/m ruby example using 3rd party client; this page is only for Thrift examples.
http://wiki.apache.org/cassandra/ClientExamples?action=diff&rev1=48&rev2=49
--------------------------------------------------
StorageService.instance().stopClient();
}}}
A caveat of doing things this way is that a client cannot go up and down, and then up again without shutting down the entire VM. I.e., you can't initClient(), stopClient() and then initClient() again.
-
- == 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 ==
{{{