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. HTML:减少页面加载时间的方法

    1. 重复的HTTP请求数量应尽量减少 (1)减少调用其他页面.文件的数量. (2)在使用css格式时,常会采用background载入图形文件,而每个background的图像都会产生1次HTTP ...

  2. VMware workstation 与 VMware GSX Server 的区别

    http://xsagaplus.iteye.com/blog/358917VMware是提供一套虚拟机解决方案的软件,主要产品分为如下三个. VMware-ESX-Server  这个版本并不需要操 ...

  3. 也来学学插件式开发续-利用MEF

    前面一个博客:也来学学插件式开发中很多朋友留言说可以用MEF来实现.于是我就试着用MEF实现了一下. 步骤和上一篇差不多,只是加载插件的方式有所不同.这只是一个自己的示例程序,肯定有很多不足之处,欢迎 ...

  4. Linux-支持中文

    转自:http://www.centoscn.com/CentosBug/osbug/2014/0919/3776.html 英文版的linux系统默认不支持中文显示 那么如何显示中文呢? 可以使用l ...

  5. 在rhel6上安装Python 2.7和Python 3.3

    安装前,操作系统软件包准备编译python要安装development tools.此外,还要安装一些其他的libs,没有这些libs,python的interpreter可能会无法正常工作 # yu ...

  6. Linux时间子系统(四) timekeeping

    一.前言 timekeeping模块是一个提供时间服务的基础模块.Linux内核提供各种time line,real time clock,monotonic clock.monotonic raw ...

  7. winform dataGridView DataGridViewComboBoxColumn 下拉框事件

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

  8. python标准库介绍——23 UserString 模块详解

    ==UserString 模块== (2.0 新增) ``UserString`` 模块包含两个类, //UserString// 和 //MutableString// . 前者是对标准字符串类型的 ...

  9. 浅谈Javascript中的void操作符

    由于JS表达式偏啰嗦,于是最近便开始采用Coffeescript来减轻负担.举个栗子,当我想取屋子里的第一条dog时,首先要判断house对象是否存在,然后再判断house.dogs是否存在,最后取h ...

  10. 配置 Sliverlight 跨域访问策略

    Silverlight程序在访问非本域资源时,需要在相应的域根目录下建立跨域访问策略文件才能进行访问. 文件名:clientaccesspolicy.xml 文件内容: <?xml versio ...