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. 交叉编译OpenWrt 定制固件

    在Centos7上交叉编译生成OpenWrt固件 安装ss-* 获取最新的ss, 当前是 wget https://github.com/shadowsocks/shadowsocks-libev/a ...

  2. JavaScript-jQuery插件开发全解析

    摘自:http://www.iteye.com/topic/545971 jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法 ...

  3. 【转载】spring mvc 使用session

    http://home.51.com/gaoyangboy/diary/item/10036382.html Spring2.5 访问 Session 属性的四种策略 Posted on 2008-1 ...

  4. [转载]在rhel 6 x86_64 上安装oracle 11g xe

    原文地址:在rhel 6 x86_64 上安装oracle 11g xe作者:pccom Oracle 11g xe for linux目前只有x86_64 版本,没有i386, i686 版本,如果 ...

  5. 最新最全的iOS手机支付总结

    关于手机支付,我想简单总结一下,我想主要分成三大类: 第一类,就是我们最常见的应用内支付(IAP),例如APPStore里面我们可以付费下载一些APP或者游戏. 第二类,就是我们经常使用第三方支付,例 ...

  6. Ubuntu Pycharm不能同时选中多行解决方法

    转自http://blog.csdn.net/yaoqi_isee/article/details/77866309 问题描述 Pycharm和Sublime有一个很好用的特性就是可以同时选中多行进行 ...

  7. -no-xrender will disable the qtwebkit

    -no-xrender will disable the qtwebkit         apt-get install libxrender-dev 来自为知笔记(Wiz)

  8. C#实现WinForm下DataGridView控件的拷贝和粘贴

    DataGridView控件应该是数据库应用系统最常用的控件之一,其方便性不言而喻的.往往用户在使用过程中会提出"从DataGridView空间 中拷贝数据或是向某个DataGridView ...

  9. react dva 的 connect 与 @connect

    https://dvajs.com/guide/introduce-class.html#connect-方法 connect的作用是将组件和models结合在一起.将models中的state绑定到 ...

  10. Latex算法伪代码使用总结

    Latex伪代码使用总结 algorithmicx例子 相应代码: \documentclass[11pt]{ctexart} \usepackage[top=2cm, bottom=2cm, lef ...