java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

php 操作Hbase函数手册

$tablename='test';
$atrribute = array();

1.写入数据

$row = 'stu1'; //行名字
$mutations = array(
    new Mutation(array(
        'column' => 'cf:math',
        'value' => '90'
    )),
);
try {
    $client->mutateRow($tablename, $row, $mutations, $atrribute);
} catch (Exception $e) {
    var_dump($e);//这里自己打log
}

2.php读Hbase数据

$result = $client->getRow($tablename, $row, $atrribute);
var_dump($result);

3. php删除Hbase数据

 $client->deleteAllRow($tablename, $row, $atrribute);

4. php 读取一条Hbase数据

 $result = $client->getRow($tablename, $row, $atrribute);
 var_dump($result);

5. php扫描Hbase里stu开头的数据

$scan = $client->scannerOpenWithPrefix($tablename, 'stu', array(),array());
$nbRows = 100;
$arr = $client->scannerGetList($scan, $nbRows);
echo 'count of result :'.count($arr)."\n";
var_dump($arr);
foreach ($arr as $k => $TRowResult) {
   echo "\trow:$TRowResult->row\tcolumns(array):";
   foreach ($TRowResult->columns as $key => $value) {
      echo "key:$key\tvalue:$value->value\ttimestamp:$value->timestamp\n";
   }
}

6. php 范围扫描 stu0 到 stu3的数据

$scan = $client->scannerOpenWithStop($tablename, 'stu0', 'stu3', array(), array());
$nbRows = 100;
$arr = $client->scannerGetList($scan, $nbRows);
echo 'count of result :'.count($arr)."\n";
var_dump($arr);
foreach ($arr as $k => $TRowResult) {
   echo "\trow:$TRowResult->row\tcolumns(array):";
   foreach ($TRowResult->columns as $key => $value) {
      echo "key:$key\tvalue:$value->value\ttimestamp:$value->timestamp\n";
   }
}

7. Hbase的 Increment 操作
一种原子操作,每次增加一定数字

$row = 'stu7';
try {
$newCount = $client->atomicIncrement($tablename, $row, 'cf:count', 1);
} catch (Exception $e) {
    var_dump($e);
}
echo "new count $newCount\n";

8. php写入一个long型数据到hbase

$row = 'stu6';
$value = pack("J", 4567);

$mutations = array(
   new Mutation(array(
        'column' => 'cf:math',
        'value' => $value
    )),
);
try {
    $client->mutateRow($tablename, $row, $mutations, $atrribute);
} catch (Exception $e) {
    var_dump($e);
}
echo "---read data and print it as long ---\n";
$result = $client->getRow($tablename, $row, $atrribute);
foreach ($result[0]->columns as $key => $value) {
  
  $count = unpack("J*mycount", $value->value);
  var_dump($count);
}


This entry was posted in PHP and tagged . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/php-hbase-function/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

One Response to php 操作Hbase函数手册

  1. Lzsen says:

    除了这些操作,还没有文档之类的呢

Leave a Reply