Search code examples
phpdatabasenosqlcassandraphpcassa

Show all keys with phpcassa


I'm fairly new to cassandra but i have making good progress so far.

$conn = new ConnectionPool('Cluster');
$User = new ColumnFamily($conn, 'User');

$index_exp = CassandraUtil::create_index_expression('email', 'John@dsaads.com');
$index_clause = CassandraUtil::create_index_clause(array($index_exp));
$rows = $User->get_indexed_slices($index_clause);

foreach($rows as $key => $columns) {
echo $columns['name']."<br />";
}

Im using this type of query to get specific date from somebodys email adress. However, i now want to do 2 things.

  1. Count every user in the database and display the number
  2. List every user in the database with $columns['name']." ".$columns['email']

In mysql i would just remove the 'where attribute' from the select query, however i think its a little bit more complicated here?


Solution

  • In Cassandra there's no easy way to count all of the rows. You basically have to scan everything. If this is something that you want to do often, you're doing it wrong. Example code:

    $rows = $User->get_range("", "", 1000000);
    $count = 0;
    foreach($rows as $row) {
        $count += 1;
    }
    

    The second answer is similar:

    $rows = $User->get_range("", "", 1000000, null, array("name", "email"));
    foreach($rows as $key => $columns) {
        echo $columns["name"]." ".$columns["email"];
    }