phpcassa cassandra批量突变

时间:2012-01-11 11:32:17

标签: cassandra phpcassa

你能在phpcassa中提供一个batch_mutate()函数的例子吗?

无法理解如何使用此功能并且没有找到足够的信息。

我也想知道如何将它与计数器一起使用

提前致谢。

2 个答案:

答案 0 :(得分:3)

“从多个键中删除数据”:

function batch_remove($key=null, $columns=null, $super_column=null, $write_consistency_level=null) {

    $timestamp = CassandraUtil::get_time();
    $deletion = new cassandra_Deletion();
    $deletion->timestamp = $timestamp;

    if ($super_column !== null) $deletion->super_column = $this->pack_name($super_column, true);
    else $deletion->super_column = null;

    if ($columns !== null) {
        $predicate = $this->create_slice_predicate($columns, '', '', false, self::DEFAULT_COLUMN_COUNT);
        $deletion->predicate = $predicate;
    }

    $mutation = new cassandra_Mutation();
    $mutation->deletion = $deletion;

    if (is_array($key) && count($key) >= 1) {

        $mut_map = array();
        foreach($key as $v) {
            $packed_key[$v] = $this->pack_key($v);
            $mut_map[$v] = array($this->column_family => array($mutation));
        }

        return $this->pool->call("batch_mutate", $mut_map, $this->wcl($write_consistency_level));

    } else return false;

}

//delete name1, name2, name3 from key1, key2 in a single call
$column_family->batch_remove(array(key1, key2), array(name1, name2, name3));

答案 1 :(得分:2)

    使用PHPCassa时,
  1. 计数器上的batch_mutate尚不可用:https://github.com/thobbs/phpcassa/issues/31
  2. batch_mutate正在运行,根据教程:http://thobbs.github.com/phpcassa/tutorial.html
  3. “插入数据”:

     $row1 = array('name1' => 'val1', 'name2' => 'val2');
     $row2 = array('foo' => 'bar');
     $column_family->batch_insert(array('row1' => $row1, 'row2' => $row2);