Skip to content

Instantly share code, notes, and snippets.

@pablete
Created November 25, 2009 14:22
Show Gist options
  • Save pablete/242734 to your computer and use it in GitHub Desktop.
Save pablete/242734 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment