/** * Prepare Cassandra required configuration and connect to node */ private function _LoadAndConnectToCass() { $cassConf = $this->_config['cassandra']; if (!$cassConf) { throw new Exception('Missing cassandra config'); } $this->_cassandraInst = Cassandra::createInstance(array(array('host' => $cassConf['host'], 'port' => $cassConf['port'], 'use-framed-transport' => $cassConf['use_framed_transport'], 'send-timeout-ms' => $cassConf['send_timeout_ms'], 'receive-timeout-ms' => $cassConf['receive_timeout_ms']))); $this->_cassandraInst->useKeyspace($this->_config['default']['keyspace']); $this->_cassandraInst->setMaxCallRetries(5); }
public function setup() { if (function_exists('apc_clear_cache')) { apc_clear_cache(); } $this->servers = array(array('host' => '127.0.0.1', 'port' => 9160)); $this->cassandra = Cassandra::createInstance($this->servers); $this->cassandra2 = Cassandra::createInstance($this->servers, 'Another'); if (!self::$setupComplete) { try { $this->cassandra->dropKeyspace('CassandraModelTest'); } catch (Exception $e) { } $this->cassandra->setMaxCallRetries(5); $this->cassandra->createKeyspace('CassandraModelTest'); $this->cassandra->useKeyspace('CassandraModelTest'); $this->cassandra->createStandardColumnFamily('CassandraModelTest', 'user', array(array('name' => 'email', 'type' => Cassandra::TYPE_UTF8), array('name' => 'name', 'type' => Cassandra::TYPE_UTF8, 'index-type' => Cassandra::INDEX_KEYS, 'index-name' => 'NameIdx'), array('name' => 'age', 'type' => Cassandra::TYPE_INTEGER, 'index-type' => Cassandra::INDEX_KEYS, 'index-name' => 'AgeIdx'))); /* $this->cassandra->createSuperColumnFamily( 'CassandraModelTest', 'cities', array( array( 'name' => 'population', 'type' => Cassandra::TYPE_INTEGER ), array( 'name' => 'comment', 'type' => Cassandra::TYPE_UTF8 ) ), Cassandra::TYPE_UTF8, Cassandra::TYPE_UTF8, Cassandra::TYPE_UTF8, 'Capitals supercolumn test', 1000, 1000, 0.5 ); */ self::$setupComplete = true; } else { $this->cassandra->useKeyspace('CassandraModelTest'); } $this->cassandra2->useKeyspace('CassandraModelTest'); }
<?php // show all the errors error_reporting(E_ALL); // the only file that needs including into your project require_once 'Cassandra.php'; // list of seed servers to randomly connect to // all the parameters are optional and default to given values $servers = array(array('host' => '127.0.0.1', 'port' => 9160, 'use-framed-transport' => true, 'send-timeout-ms' => 1000, 'receive-timeout-ms' => 1000)); // create a named singleton, the second parameter name defaults to "main" // you can have several named singletons with different server pools $cassandra = Cassandra::createInstance($servers); // at any point in code, you can get the named singleton instance, the name // again defaults to "main" so no need to define it if using single instance $cassandra2 = Cassandra::getInstance(); // drop the example keyspace and ignore errors should it not exist try { $cassandra->dropKeyspace('CassandraExample'); } catch (Exception $e) { } // create a new keyspace, accepts extra parameters for replication options // normally you don't do it every time $cassandra->createKeyspace('CassandraExample'); // start using the created keyspace $cassandra->useKeyspace('CassandraExample'); // if a request fails, it will be retried for this many times, each time backing // down for a bit longer period to prevent floods; defaults to 5 $cassandra->setMaxCallRetries(5); // create a standard column family with given column metadata $cassandra->createStandardColumnFamily('CassandraExample', 'user', array(array('name' => 'name', 'type' => Cassandra::TYPE_UTF8, 'index-type' => Cassandra::INDEX_KEYS, 'index-name' => 'NameIdx'), array('name' => 'email', 'type' => Cassandra::TYPE_UTF8), array('name' => 'age', 'type' => Cassandra::TYPE_INTEGER, 'index-type' => Cassandra::INDEX_KEYS, 'index-name' => 'AgeIdx'))); // create a standard column family with given column metadata
/** * @expectedException CassandraInvalidRequestException */ public function testExceptionIsThrownIfKeyspaceNotSetOnCall() { $cassandra = Cassandra::createInstance($this->servers, 'other'); $cassandra->call('get'); }