1 计数器
计数器可以方便、快速地进行计数操作,而且避免了加锁等保证了原子性的操作。
 
1.1 Java API 操作 HBase 计数器
public Result increment(final Increment increment)
public long incrementColumnValue(final byte [] row, final byte [] family,
      final byte [] qualifier, final long amount)
public long incrementColumnValue(final byte [] row, final byte [] family,
      final byte [] qualifier, final long amount, final Durability durability)
 
从这 3 个 HBase 提供的 计数器 API 来看,可以知道有 单列计数器 和 多列计数器
 
pv + 1 的 Java 示例如下 : 
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), 1L);
 
1.2 Shell 操作 HBase 计数器
hbase(main):011:0> incr 'user', 'row-zhangsan-001', 'cf1:pv', 10
hbase(main):012:0> incr 'user', 'row-zhangsan-001', 'cf1:pv', -1
hbase(main):013:0> scan 'user'
ROW                                                 COLUMN+CELL                                                                                                                                         
 row-zhangsan-001                                   column=cf1:pv, timestamp=1438853474770, value=\x00\x00\x00\x00\x00\x00\x00\x09
hbase(main):014:0> get_counter 'user', 'row-zhangsan-001', 'cf1:pv', ''
COUNTER VALUE = 9
 
// 看下面提示,给的例子只要3个参数,为什么我要打4个才能够用???
hbase(main):015:0> get_counter 'user', 'row-zhangsan-001', 'cf1:pv'
ERROR: wrong number of arguments (3 for 4)
Here is some help for this command:
Return a counter cell value at specified table/row/column coordinates.
A cell cell should be managed with atomic increment function oh HBase
and the data should be binary encoded. Example:
  hbase> get_counter 'ns1:t1', 'r1', 'c1'
  hbase> get_counter 't1', 'r1', 'c1'
The same commands also can be run on a table reference. Suppose you had a reference
t to table 't1', the corresponding command would be:
  hbase> t.get_counter 'r1', 'c1' 
 
hbase(main):055:0> get 'test_icv_tmp_1', 'row-zhangsan-001', 'cf1:pv'
COLUMN                                              CELL                                                                                                                                                   
 cf1:pv                                             timestamp=1438853974733, value=\x00\x00\x00\x00\x00\x00\x00\x0A                                                                                       
1 row(s) in 0.0080 seconds
 
hbase(main):056:0> 
 
 
1.3 单列计数器
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), 10L); // pv +10
_hTable.incrementColumnValue(Bytes.toBytes("row-zhangsan-001"), Bytes.toBytes("info"), Bytes.toBytes("pv"), -1L); // pv -1
 
1.4 多列计数器
pv +2 的同时,uv 同时 +1
Increment increment = new Increment(Bytes.toBytes("row"));
increment.addColumn(Bytes.toBytes("info"), Bytes.toBytes("pv"), 1L); // pv +2
increment.addColumn(Bytes.toBytes("info"), Bytes.toBytes("uv"), 1L); // uv +1
_hTable.increment(increment);

hbase计数器的更多相关文章

  1. Hbase 计数器

    Hbase计数器可以用于统计用户数,点击量等信息 基本操作 可以使用incr操作计数器,incr语法格式如下: incr '<table>', '<row>', '<co ...

  2. HBase - 计数器 - 计数器的介绍以及使用 | 那伊抹微笑

    博文作者:那伊抹微笑 csdn 博客地址:http://blog.csdn.net/u012185296 itdog8 地址链接 : http://www.itdog8.com/thread-215- ...

  3. HBase之计数器

    HBase计数器 #创建counters表 列族['daily','weekly','monthly'] hbase(main):001:0> create 'counters','daily' ...

  4. Hbase学习04

    3.2.4 反向时间戳 反向扫描API HBASE-4811(https://issues.apache.org/jira/browse/HBASE-4811)实现了一个API来扫描一个表或范围内的一 ...

  5. HBase常用shell操作

    行(row),列(Column),列蔟(Column Family),列标识符(Column Qualifier)和单元格(Cell) 行:由一个个行键(rowkey)和一个多个列组成.其中rowke ...

  6. hbase开发实例

    1.put/checkAndPut package com.testdata; import java.io.IOException; import org.apache.hadoop.conf.Co ...

  7. HBase与MongDB等NoSQL数据库对照

    HBase概念学习(十)HBase与MongDB等NoSQL数据库对照 转载请注明出处: jiq•钦's technical Blog - 季义钦 一.开篇 淘宝之前使用的存储层架构一直是MySQL数 ...

  8. HBase Shell 常见操作

    1.一般操作 status 查看状态 version 查看HBase版本 2.DDL操作 create 'member','member_id','address','info' 创建了一个membe ...

  9. HBase使用场景和成功案例 (转)

    HBase 使用场景和成功案例 有时候了解软件产品的最好方法是看看它是怎么用的.它可以解决什么问题和这些解决方案如何适用于大型应用架构,能够告诉你很多.因为HBase有许多公开的产品部署,我们正好可以 ...

随机推荐

  1. C#线程访问winform窗体控件

    参考地址:http://www.cnblogs.com/jason-liu-blogs/archive/2012/09/08/2677008.html 添加: public Form() { Init ...

  2. docker登录没有配置https的harbor镜像仓库

    已经搭建harbor 仓库 ,域名  172.16.1.99 出现问题: 客户端尝试登录 仓库 [root@localhost docker]# docker login 172.16.1.99:80 ...

  3. Linux中断 - IRQ Domain介绍

    一.概述 在linux kernel中,我们使用下面两个ID来标识一个来自外设的中断: 1.IRQ number.CPU需要为每一个外设中断编号,我们称之IRQ Number.这个IRQ number ...

  4. OJ刷题---罗马数字转十进制

    题目要求: 输入代码: #include<iostream> using namespace std; int main() { int i,j,n,k; int num[7]= {1, ...

  5. winform dataGridView DataGridViewComboBoxColumn 下拉框事件

    有一个dataGridView ,有一列是DataGridViewComboBoxColumn .用动态绑定,在绑定数据的时候.我们也给这一列绑定数据 在dataGridView的RowsAdded事 ...

  6. C#--索引

    索引是一组get和set访问器,类似于属性的访问器. 索引和属性在很多方面是相似的. 和属性一样,索引不用分配内存来存储: 索引和属性都主要被用来访问其他数据成员,这些成员和他们关联,他们为这些成员提 ...

  7. JavaScript Interview Questions: Event Delegation and This

    David Posin helps you land that next programming position by understanding important JavaScript fund ...

  8. enumerate的简单使用

    l = [11,22,33,55,"ss","zz"] for i,v in enumerate(l): print(i,v) #打印结果: # 0 11 # ...

  9. Excel中不常用的一些公式用法

    INDIRECT函数 http://baike.baidu.com/view/3222185.htm 用于使用单元格内容拼凑公式的情况. 1.采用  [工作表名]!单元格名  的形式读取内容: 2.所 ...

  10. [Python]南邮OJ代码备份爬虫

    之前看过Python学习的经验,说以project为导向学习. 自己分析了一下,一般接触Python的都有一定的其它语言基础,对于程序设计的基本逻辑,语法都有一个大概的了解.而Python这样的脚本语 ...