-
Notifications
You must be signed in to change notification settings - Fork 11
Examples
mjpearson edited this page Sep 13, 2010
·
29 revisions
// create named connections against PANDRA_PORT_DEFAULT (9160) PandraCore::Connect('default', 'host1'); PandraCore::Connect('default1', 'host2'); PandraCore::Connect('default2', 'host3'); // last connected becomes the active connection // to set active node PandraCore::setActive('default'); // read/write modes. // Available types - PANDRA_MODE_ACTIVE, PANDRA_MODE_ROUND, PANDRA_MODE_RANDOM // default read/write modes are _ACTIVE PandraCore::setReadMode(PANDRA_MODE_RANDOM); PandraCore::setWriteMode(PANDRA_MODE_ROUND); // get active CassandraClient (Thrift) $client = PandraCore::getClient(); // disconnections, either named or everything in the cluster PandraCore::disconnect('default'); // closes named node PandraCore::disconnectAll(); // Sets global default consistency level for reads and writes // Consistency level should be tweaked to replication factor PandraCore::setConsistency(cassandra_ConsistencyLevel::ONE);
class MyObject extends PandraColumnFamily { var $keySpace = 'Keyspace1'; var $name = 'Standard1'; public function init() { $this->addColumn('column1'); } } $keyID = 'PandraExample_CF'; PandraCore::connect('default', 'localhost'); // Create and save our test object $mo = new MyObject(); $mo->keyID = $keyID; $mo->setColumn('column1', 'TEST DATA'); $mo->save(); unset($mo); // load ColumnFamily test object $mo = new MyObject($keyID); echo 'RETRIEVED'.$mo->column_column1.'<BR>';
class Address extends PandraSuperColumn { public function init() { $this->addColumn('city', 'string'); $this->addColumn('street', 'string'); $this->addColumn('zip', 'int'); } } class Addresses extends PandraSuperColumnFamily { var $keySpace = 'Keyspace1'; var $name = 'Super1'; public function init() { $this->addSuper(new Address('homeAddress')); $this->addSuper(new Address('workAddress')); } } $keyID = 'kenlogin'; $addrs = new Addresses(); $addrs->keyID = $keyID; // home address $homeAddr = $addrs->getColumn('homeAddress'); $homeAddr->setColumn('city', 'san francisco'); $homeAddr->setColumn('street', '1234 x street'); $homeAddr->setColumn('zip', '94107'); // work address $workAddr = $addrs->getColumn('workAddress'); $workAddr->setColumn('city', 'san jose'); $workAddr->setColumn('street', '9876 y drive'); // custom labelled supercolumn $customAddr = new Address(''customAddress'); $customAddr->setColumn('city', 'another city'); $addrs->addSuper($customAddr); $addrs->save();
// super_ and column_ magic methods $addrs->super_homeAddress->column_city = 'Sydney'; echo "MAGIC PATH : ".$addrs->super_homeAddress->column_city."<br>"; // array syntax $addrs['homeAddress']['city'] = 'San Francisco'; echo "ARRAY PATH : ".$addrs['homeAddress']['city']."<br>"; // get method (for IDE autocompletes) $addrs->getSuper('homeAddress')->getColumn('city')->setValue('Siem Reap'); echo "GET PATH : ".$addrs->getSuper('homeAddress')->getColumn('city')->value."<br>"; // all methods will validate from the type definition on the column // be sure to check the column (family) error methods