Dear Wiki user,

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

The following page has been changed by Chris Goffinet:
http://wiki.apache.org/cassandra/ClientExamples

------------------------------------------------------------------------------
  }
  }}}
  
+ == Java ==
+ {{{
+ #!/usr/bin/env python
+ # encoding: utf-8
+ """
+ Sample Cassandra Client
+ 
+ Created by Chris Goffinet on 2009-08-26.
+ """
+ from thrift import Thrift
+ from thrift.transport import TTransport
+ from thrift.transport import TSocket
+ from thrift.protocol import TBinaryProtocol
+ from cassandra import Cassandra
+ from cassandra.ttypes import *
+ import time, pprint
+ 
+ def main():
+     socket = TSocket.TSocket("localhost", 9160)
+     transport = TTransport.TBufferedTransport(socket)
+     protocol = TBinaryProtocol.TBinaryProtocol(transport)
+     client = Cassandra.Client(protocol)
+     pp = pprint.PrettyPrinter(indent = 2)
+ 
+     keyspace = "Keyspace1"
+     column_path = ColumnPath(column_family="Standard1",column="email")
+     key = "1"
+     value = "[email protected]"
+     timestamp = time.time()
+     
+     try:
+         transport.open()
+         """ Insert the data into Keyspace 1 """
+         client.insert(keyspace, key, column_path, value, timestamp, 
ConsistencyLevel.ZERO);
+         
+         """" Query for data """
+         column_parent = ColumnParent(column_family="Standard1")
+         slice_range = SliceRange(start="", finish="")
+         predicate = SlicePredicate(slice_range=slice_range)
+         
+         result = client.get_slice(keyspace, key, column_parent, predicate, 
ConsistencyLevel.ONE);
+         pp.pprint(result)
+ 
+     except Thrift.TException, tx:
+         print 'Thrift: %s' % tx.message
+     finally:
+         transport.close()
+ 
+ if __name__ == '__main__':
+     main()
+ }}}
+ 

Reply via email to