Hbase 计数器
Hbase计数器可以用于统计用户数,点击量等信息
基本操作
可以使用incr操作计数器,incr语法格式如下:
incr '<table>', '<row>', '<column>', |<increment-value>|
然后使用get_counter可以获取对应的计数器的值
不用初始化计数器,第一次使用计数器时,计数器被自动设置为0
eg:
对于wishTest1表
incr 'wishTest1','2','score:Math',1 incr 'wishTest1','2','score:Math',1 get_counter 'wishTest1','2','score:Math'
结果如下:

hbase(main):004:0> incr 'wishTest1','2','score:Math',1
COUNTER VALUE = 1 hbase(main):005:0> incr 'wishTest1','2','score:Math',1
COUNTER VALUE = 2 hbase(main):007:0> get_counter 'wishTest1','2','score:Math'
COUNTER VALUE = 2 hbase(main):008:0>

增大计数的递增值:

hbase(main):001:0> incr 'wishTest1','2','score:Math',10
COUNTER VALUE = 12 hbase(main):002:0> incr 'wishTest1','2','score:Math',10
COUNTER VALUE = 22 hbase(main):003:0> get_counter 'wishTest1','2','score:Math'
COUNTER VALUE = 22

使用API操作计数器
使用table.incrementColumnValue()
eg:

String tableName = "wishTest1";
HTablePool pool = new HTablePool(cfg, 1000);
try {
long count1 = pool.getTable(tableName).incrementColumnValue(Bytes.toBytes("2"),Bytes.toBytes("score"),Bytes.toBytes("Math"),1);
long count2 = pool.getTable(tableName).incrementColumnValue(Bytes.toBytes("2"),Bytes.toBytes("score"),Bytes.toBytes("Math"),1);
long currentCount = pool.getTable(tableName).incrementColumnValue(Bytes.toBytes("2"),Bytes.toBytes("score"),Bytes.toBytes("Math"),0);
System.out.println("count1: "+count1);
System.out.println("count2: "+count2);
System.out.println("currentCount: "+currentCount);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

输出:
count1: 23
count2: 24
currentCount: 24
Hbase 计数器的更多相关文章
- hbase计数器
1 计数器 计数器可以方便.快速地进行计数操作,而且避免了加锁等保证了原子性的操作. 1.1 Java API 操作 HBase 计数器 public Result increment(final ...
- HBase - 计数器 - 计数器的介绍以及使用 | 那伊抹微笑
博文作者:那伊抹微笑 csdn 博客地址:http://blog.csdn.net/u012185296 itdog8 地址链接 : http://www.itdog8.com/thread-215- ...
- HBase之计数器
HBase计数器 #创建counters表 列族['daily','weekly','monthly'] hbase(main):001:0> create 'counters','daily' ...
- Hbase学习04
3.2.4 反向时间戳 反向扫描API HBASE-4811(https://issues.apache.org/jira/browse/HBASE-4811)实现了一个API来扫描一个表或范围内的一 ...
- HBase常用shell操作
行(row),列(Column),列蔟(Column Family),列标识符(Column Qualifier)和单元格(Cell) 行:由一个个行键(rowkey)和一个多个列组成.其中rowke ...
- hbase开发实例
1.put/checkAndPut package com.testdata; import java.io.IOException; import org.apache.hadoop.conf.Co ...
- HBase与MongDB等NoSQL数据库对照
HBase概念学习(十)HBase与MongDB等NoSQL数据库对照 转载请注明出处: jiq•钦's technical Blog - 季义钦 一.开篇 淘宝之前使用的存储层架构一直是MySQL数 ...
- HBase Shell 常见操作
1.一般操作 status 查看状态 version 查看HBase版本 2.DDL操作 create 'member','member_id','address','info' 创建了一个membe ...
- HBase使用场景和成功案例 (转)
HBase 使用场景和成功案例 有时候了解软件产品的最好方法是看看它是怎么用的.它可以解决什么问题和这些解决方案如何适用于大型应用架构,能够告诉你很多.因为HBase有许多公开的产品部署,我们正好可以 ...
随机推荐
- provider: 命名管道提供, error: 40 - 无法打开 SQL Server 联系)
李和server连接错误. 在连接 SQL Server 2005 时刻.在默认设置 SQL Server 不同意的远程连接可能导致此故障. (provider: 命名管道提供, error: 40 ...
- XTU OJ 1210 Happy Number (暴力+打表)
Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...
- 使用 Java 配置进行 Spring bean 管理--转
概述 众所周知,Spring 框架是控制反转 (IOC) 或依赖性注入 (DI) 模式的推动因素,而这种推动是通过基于容器的配置实现的.过去,Spring 允许开发人员使用基于 XML 的配置,通过利 ...
- 自定义filter包
在有些时候,你可能需要以你的所有项目进行全局的过滤. 因为你的项目可以设计到互相的依赖和调用 . 修改在tomcat下的conf下的web.xml文件.和在原来的web-inif下的修改一样,添加fi ...
- AutoBackupForApps
This sample demonstrates how to selectively disable Automatic Backups in Android M, either by adjust ...
- 中国剩余定理模板poj1006
#include <cstdio> #include <iostream> #include <cstring> #include <cmath> #i ...
- Android手机适配——UI图片适配
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/50727753 在Android项目当中,drawable文件夹都是用来放置图片资源 ...
- Linq101-Miscellaneous
using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Miscell ...
- IIS 服务器 支持.apk文件的下载
IIS服务器不能下载.apk文件的解决办法:既然.apk无法下载是因为没有MIME,那么添加一个MIME类型就可以了 随着智能手机的普及,越来越多的人使用手机上网,很多网站也应手机上网的需要推出了网站 ...
- 网络编程Socket之UDP
服务器端实现步骤: 1. 创建 DatagramSocket,指定端口号 2. 创建 DatagramPacket 3. 接收客户端发送的数据信息 4. 读取数据 package cn.jmu.edu ...