代码如下:

<?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. python中urllib, urllib2,urllib3, httplib,httplib2, request的区别

    permike原文python中urllib, urllib2,urllib3, httplib,httplib2, request的区别 若只使用python3.X, 下面可以不看了, 记住有个ur ...

  2. 配置sql server 2000以允许远程访问 及 连接中的四个最常见错误

    地址:http://www.cnblogs.com/JoshuaDreaming/archive/2010/12/01/1893242.html 配置sql server 2000以允许远程访问适合故 ...

  3. ASPxGridView改变列颜色

    protected void ASPxGridView1_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs ...

  4. asp.net读取txt并导入数据库

    源地址:http://www.cnblogs.com/hfzsjz/p/3214649.html

  5. C++学习26 运算符重载的概念和语法

    所谓重载,就是赋予新的含义.函数重载(Function Overloading)可以让一个函数名有多种功能,在不同情况下进行不同的操作.运算符重载(Operator Overloading)也是一个道 ...

  6. Dubbo 源码安装与编译

    源码地址: https://github.com/alibaba/dubbo  需要提前准备好 Maven 环境, 相关准备方法请看: http://www.cnblogs.com/ghj1976/p ...

  7. nyoj 68 三点顺序

    点击打开链接 三点顺序 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 现在给你不共线的三个点A,B,C的坐标,它们一定能组成一个三角形,现在让你判断A,B,C是顺时针给 ...

  8. C++ STL小知识

    五种迭代器: 在STL中,迭代器主要分为5类,分别是:输入迭代器.输出迭代器.前向迭代器.双向迭代器和随机访问迭代器. 输入迭代器 :只读,支持++.==.!=: 输出迭代器 :只写,支持++: 前向 ...

  9. The Ninth Hunan Collegiate Programming Contest (2013) Problem G

    Problem G Good Teacher I want to be a good teacher, so at least I need to remember all the student n ...

  10. 一道 JavaScript 面试题

    有一道 JavaScript 面试题. f = function () { return true; }; g = function () { return false; }; (function() ...