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 Chris Goffinet
Date Thu, 27 Aug 2009 00:49:04 GMT
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

The comment on the change is:
Fixed the PHP code to use Standard1 from the config and added an include

------------------------------------------------------------------------------
  <?php
  $GLOBALS['THRIFT_ROOT'] = '/usr/share/php/Thrift';
  require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/Cassandra.php';
+ require_once $GLOBALS['THRIFT_ROOT'].'/packages/cassandra/cassandra_types.php';
  require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
  require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
  require_once $GLOBALS['THRIFT_ROOT'].'/transport/TFramedTransport.php';
@@ -36, +37 @@

    $transport->open();
    
    
-   /* Insert some data into base attributes */
+   /* Insert some data into the Standard1 column family from the default config */
    
-   // Table name specified in storage=conf.xml
+   // Keyspace specified in storage=conf.xml
-   $tableName = 'users';
+   $keyspace = 'Keyspace1';
    
    // reference to specific User id
    $keyUserId = "1";
    
    // Constructing the column path that we are adding information into.
    $columnPath = new cassandra_ColumnPath();
-   $columnPath->column_family = 'base_attributes';
+   $columnPath->column_family = 'Standard1';
    $columnPath->super_column = null;
    $columnPath->column = 'email';
    
    // Timestamp for update
    $timestamp = time();
    
-   // TODO someone who knows PHP update this to use ConsistencyLevel constants
-   $block_for = 0;
+   // We want the consistency level to be ZERO which means async operations on 1 node
+   $consistency_level = cassandra_ConsistencyLevel::ZERO;
    
    // Add the value to be written to the table, User Key, and path. 
-   $value = "daniel@example.com";
+   $value = "foobar@example.com";
-   $client->insert($tableName, $keyUserId, $columnPath, $value, $timestamp, $block_for);
+   $client->insert($keyspace, $keyUserId, $columnPath, $value, $timestamp, $consistency_level);
  
    // Add a new column path to be altered. 
    $columnPath->column = 'age';
@@ -66, +67 @@

    $timestamp = time();
    // Update the value to be inserted for the updated column Path
    $value = "24";
-   $client->insert($tableName, $keyUserId, $columnPath, $value, $timestamp, $block_for);
+   $client->insert($keyspace, $keyUserId, $columnPath, $value, $timestamp, $consistency_level);
  	
    /* Query for data */
  
    // Specify what Column Family to query against.
    $columnParent = new cassandra_ColumnParent();
-   $columnParent->column_family = "base_attributes";
+   $columnParent->column_family = "Standard1";
    $columnParent->super_column = NULL;
  
  
@@ -83, +84 @@

    list() = $predicate->column_names;
    $predicate->slice_range = $sliceRange;
  
-   $consistencyLevel = 1;
+   // We want the consistency level to be ONE which means to only wait for 1 node
+   $consistency_level = cassandra_ConsistencyLevel::ONE;
+ 
    // Issue the Query
    $keyUserId = 1;
-   $result = $client->get_slice($tableName, $keyUserId, $columnParent, $predicate, $consistencyLevel);
+   $result = $client->get_slice($keyspace, $keyUserId, $columnParent, $predicate, $consistency_level);
  
  
    print_r($result);

Mime
View raw message