public $age; } // 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); /* // drop the example keyspace and ignore errors should it not exist try { $cassandra->dropKeyspace('CassandraRowsPaginationExample'); } catch (Exception $e) {} */ // set the default connection for the model CassandraModel::setDefaultConnection($cassandra); try { // start using the created keyspace $cassandra->useKeyspace('CassandraRowsPaginationExample'); } catch (Exception $e) { // create a new keyspace, accepts extra parameters for replication options // normally you don't do it every time $cassandra->createKeyspace('CassandraRowsPaginationExample'); // use the keyspace again properly $cassandra->useKeyspace('CassandraRowsPaginationExample'); // create a standard column family with given column metadata $cassandra->createStandardColumnFamily('CassandraRowsPaginationExample', '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'))); $columns = array('name' => 'Columns test', 'age' => 99, 'email' => '*****@*****.**'); // create some example data for ($i = 0; $i < 1000; $i++) { UserModel::insert('user-' . sprintf('%04d', $i), array('name' => 'User #' . $i, 'age' => round($i / 10), 'email' => 'user-' . $i . '@cpcl.com'));
/** * Sets the default Cassandra connection to use. * * You will usually call it once during boostrapping so you wouldn't need * to set it again every time in constructor or the static methods. * * @param Cassandra $connection Connection to use by default */ public static function setDefaultConnection(Cassandra $connection) { self::$_defaultConnection = $connection; }
public function testConnectionCanBeChangedLater() { CassandraModel::setDefaultConnection($this->cassandra); $model = new UserModel(); $model->setConnection($this->cassandra2); $this->assertEquals($model->getConnection(), $this->cassandra2); }