代码如下:

<?php
class Monitor_Hbase{
private $rest_host = "http://10.99.90.39:8130/";//rest地址
private $ch;
function __construct(){ }
function post($url, $data){
$ch = curl_init();
$header_str = array("Content-Type: application/json");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'put');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_HTTPHEADER , $header_str );
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1); $output = curl_exec($ch);
curl_close($ch);
return $output;
} function rest($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Accept: application/json"));
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
} function get_range_data($table, $startRow, $endRow){
$startRow = base64_encode($startRow);
$endRow = base64_encode($endRow);
$data = sprintf('{"startRow":"%s","endRow":"%s"}',$startRow,$endRow);
$output = $this->post($this->rest_host.$table."/scanner",$data);
$output_array = explode("\r\n",$output);
$location = "";
foreach($output_array as $item){
if(strpos($item, ":")>-1){
$tmp = explode(": ",$item);
if($tmp[0] === 'Location'){
$location = $tmp[1];
} }
}
$result = $this->rest($location);
$f = ($this->prase_data(json_decode($result, true)));
return $f;
} function get_data($table, $key, $coloum){
$param = urlencode($table).'/'.urlencode($key);
if(!empty($coloum)){
$param = $param.'/'.urlencode($coloum);
}
$url = $this->rest_host.$param;
$output = $this->rest($url);
return $this->prase_data(json_decode($output,true));
} function prase_data($raw){
$result = array();
$rows = $raw['Row'];
//$raw = $raw['Row'][0]['Cell'];
foreach($rows as $row){
$key = base64_decode($row['key']);
foreach ($row['Cell'] as $item){
$col = base64_decode($item['column']);
$value = base64_decode($item['$']);
$result[$key][$col]=$value;
}
}
return $result;
} } $a = new Monitor_Hbase();
$b = $a->get_range_data('map_mobile_lighttpd_slowcount','mobile_all_201411111005','mobile_all_201411111030');
//$b = $a->get_data("nuomi_lixian_daily_count","20141026_CMNET_2G_Android_5.2.1_*","");
//$b = $a->get_data("nuomi_lixian_daily_count","20141016_ALL_CMNET_2G_Android_5.2.0","");
var_dump($b);

  

Hbase rest方式获取指定key范围内的值的更多相关文章

  1. 【转载】C#中List集合使用GetRange方法获取指定索引范围内的所有值

    在C#的List集合中有时候需要获取指定索引位置范围的元素对象来组成一个新的List集合,此时就可使用到List集合的扩展方法GetRange方法,GetRange方法专门用于获取List集合指定范围 ...

  2. 【NX二次开发】获取指定矩阵标识的矩阵值

    函数:UF_CSYS_ask_matrix_values () 函数说明:获取指定矩阵标识的矩阵值. 用法: #include <uf.h> #include <uf_csys.h& ...

  3. 如何从二维数组中的多个key中获取指定key的值?

    精华 LOVEME96 2016-10-21 10:40:19 浏览(1512) 回答(3) 赞(0) 新手求教:二维数组中一般会有多个key,如果我们要获得指定key的值,应该怎么做? 问题标签: ...

  4. 8 Hbase get方式获取数据

    package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...

  5. springMVC中不通过注解方式获取指定Service的javabean

    如TestService,其实现为TestServiceImpl,则可以通过 TestService testService = (TestService)SpringContextHolder.ge ...

  6. 获取指定key对应的node节点信息

    需求:之前写的脚本(https://www.cnblogs.com/imdba/p/10197192.html),每个node上都只有一个slot段范围的情况,本次通过测试,实现了,任意段范围的获取方 ...

  7. Java 获取指定日期范围内的每个月,每季度,每一年

    /**     *根据时间范围获得月份集     * @return     */    public static List<String> getRangeSet(String beg ...

  8. c# json转换成dynamic对象,然后在dynamic对象中动态获取指定字符串列表中的值

    using Newtonsoft.Json;using System;using System.Collections.Generic;using System.Linq;using System.T ...

  9. sql server 获取自增列下一个值或者获取指定表的主键值

    IDENT_CURRENT('TableName')为当前的最大标识值, IDENT_INCR('TableName')为设置的标识值增量, 两者相加即为下一个标识值 如: SELECT IDENT_ ...

随机推荐

  1. [MySQL] 常用SQL的优化--18.4

    这里介绍下,Insert.Group By等SQL语句的优化方法: 1.大批量数据插入 当load命令导入数据的时候,可以进行适当的设置提高导入速度. 1.1 对于MyISAM表,可以先禁用非唯一索引 ...

  2. php pcntl 多进程学习

    1.捕获子进程退出(监听SIGCHLD信号,然后调用 pcntl_wait 函数) declare(ticks=1); pcntl_signal(SIGCHLD, "sig_handler& ...

  3. jQuery部分源码帮助理解

    (function(window){})(window) 为什么要传window给jquery当参数呢? 1.为了压缩有 引用 2.加速变量的寻找,当找window对象的时候,默认从本级开始寻找,一级 ...

  4. SVN安装及常见问题解决

    一.SVN简介 SVN作为以一种崛起的版本管理工具,是CVS的接班人.对于概念性的介绍我这里就不多赘述,网上很多介绍. 工作流程如下图: 二.安装 SVN的重要性就不再赘述,这里以Versionsv1 ...

  5. Tomcat下部署多个项目

    转载地址:http://blog.csdn.net/philosophyatmath/article/details/30246631 同一端口号的多个项目部署     添加: <Context ...

  6. spring应用于web项目中

    目标: 在webapp启动的时候取到spring的applicationContext对象,并把applicationContext对象存到servletContext里面,在需要的时候直接从serv ...

  7. JAVA中日期处理

    一.日期和long类型数据的相互转换 public class Hello { public static void main(String[] args) throws Exception { // ...

  8. MongoDB添加用户

    1.添加超级管理员用户 1)切换到admin数据库 >use admin 2)添加管理员用户 >db.addUser("admin","admin" ...

  9. EL表达式结合页面JSTL使用 迭代显示表格

    1.迭代显示表格 <%@ page isELIgnored="false"%><%@ taglib uri="/WEB-INF/struts-bean. ...

  10. FileSystem实例化过程

    HDFS案例代码 Configuration configuration = new Configuration(); FileSystem fileSystem = FileSystem.get(n ...