设为首页 加入收藏

TOP

HBase---使用hbase shell和Get对象获取计数器的值
2018-12-17 01:47:14 】 浏览:46
Tags:HBase--- 使用 hbase shell Get 对象 获取 计数器

//创建一个事例表

create 'demo','example'

//初始化计算器,当用户第一次使用计数器时,计数器将自动设为0

incr 'demo','1','example:hits',1

//第二次给计数器的值加1

incr 'demo','1','example:hits',1

//获取计数器的值(注意dummy的使用)

get_counter 'demo','1','example:hits','dummy'

JAVA API示例代码

 private Configuration conf;
 private Connection conn;
 private Table table;
 conf = HBaseConfiguration.create();
 // zookeeper地址
 conf.set("hbase.zookeeper.quorum", "master");
 // zookeeper端口
 conf.set("hbase.zookeeper.property.clientPort", "2181");
 conn = ConnectionFactory.createConnection(conf);
 table = conn.getTable(TableName.valueOf("word"));
 Get get = new Get(Bytes.toBytes("1"));
 get.addColumn(Bytes.toBytes("example"), Bytes.toBytes("hits"));
 Result result = table.get(get);
 System.out.println(Bytes.toLong(result.getValue(Bytes.toBytes("example"), Bytes.toBytes("hits"))));

注意:输出语句中对getValue的值进行转换时必须使用Bytes.toLong()方法,否则结果报错,一直为0.

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇基于HBase做Storm 实时计算指标存.. 下一篇hbase 源代码分析 (9) hbase启..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目