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 BaptisteLepilleur
Date Fri, 05 Feb 2010 14:30:56 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 BaptisteLepilleur.
The comment on this change is: Fixed formatting of the python example.
http://wiki.apache.org/cassandra/ClientExamples?action=diff&rev1=47&rev2=48

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

  
  `shell> thrift --gen rb:new_style cassandra.thrift`
  
+ {{{
- {{{#!/usr/bin/env ruby require './cassandra' require './cassandra_constants' require './cassandra_types'
require 'pp'
+ #!/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
  
@@ -335, +336 @@

  
   . puts "Key not found."
  
- end }}}
+ end 
+ }}}
  
  == Python ==
- {{{#!/usr/bin/env python # encoding: utf-8 """ Sample Cassandra Client
+ {{{
+ #!/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.TBinaryProtocol
import TBinaryProtocolAccelerated from cassandra import Cassandra from cassandra.ttypes import
* import time, pprint
+ 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.TBinaryProtocol 
+ import TBinaryProtocolAccelerated from cassandra 
+ import Cassandra from cassandra.ttypes 
+ import * import time, pprint
  
  def main():
- 
-  . socket = TSocket.TSocket("localhost", 9160) transport = TTransport.TBufferedTransport(socket)
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport) client = Cassandra.Client(protocol)
-  pp = pprint.PrettyPrinter(indent = 2) keyspace = "Keyspace1" column_path = ColumnPath(column_family="Standard1",column="email")
key = "1" value = " foobar@example.com " timestamp = time.time() try:
+     socket = TSocket.TSocket("localhost", 9160) 
+     transport = TTransport.TBufferedTransport(socket) 
+     protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport) 
+     client = Cassandra.Client(protocol)
+     pp = pprint.PrettyPrinter(indent = 2) 
+     keyspace = "Keyspace1" 
+     column_path = ColumnPath(column_family="Standard1",column="email") 
+     key = "1" 
+     value = " foobar@example.com " 
+     timestamp = time.time() 
+     try:
+         transport.open()
-   . transport.open() """ Insert the data into Keyspace 1 """
+         """ 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)
+         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:
+     except Thrift.TException, tx:
-   . print 'Thrift: %s' % tx.message
+         print 'Thrift: %s' % tx.message
-  finally:
+     finally:
-   . transport.close()
+         transport.close()
  
  if __name__ == '__main__':
- 
-  . main()
+   main()
  
  }}}
  

Mime
View raw message