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. 每一个软件开发人员绝对必须掌握的关于 Unicode 和字符集的最基础的知识

    2013-02-05 14:18 48人阅读 评论(0) 收藏 举报 关键字:     Unicode, Character Set, 字符集, UTF-8, ANSI, ASCII, UTF-7   ...

  2. C#基础蛋疼到爆的Byte类型表数范围之网兜毛衣见解……

    事实上写这篇对Byte类型表数范围的文章,真的是蛋疼+蛋疼+蛋疼,每每看到Byte表数范围这一块.都对-128如此的陌生与迷茫.操蛋的Byte,操蛋的人生-- 熊孩子出场:Byte 恶作剧结果:表数范 ...

  3. supervisor介绍与安装

    前言 今天同事让我帮忙安装一个叫supervisor的软件,但自己确实没接触过这个软件 自己做一下学习的记录 我首先是查询了一下supervisor的官网,初步认识一下这个软件 Supervisor是 ...

  4. Python 绘图库的使用:matplotlib

    Matplotlib 官方API地址:https://matplotlib.org/ 例子: import matplotlib.pyplot as plt num_list=[1.5,0.6,7.8 ...

  5. iOS10:CallKit的简单应用

    CallKit 这个开发框架,能够让语音或视讯电话的开发者将 UI 界面整合在 iPhone 原生的电话 App 中.将允许开发者将通讯 App 的功能内建在电话 App 的“常用联络资讯”,以及“通 ...

  6. Linux Shell之表达式

    严格来说,shell中没有表达式的概念.Shell本身事实上仅仅是一堆命令的集合.当然也不是胡乱的堆在一起.而是有一定的组织.仅仅是这个组织不那么严谨.所以本文不是要真的总结所谓的表达式,而是把she ...

  7. Python 列表 count() 方法

    描述 Python 列表 count() 方法用于统计某个元素在列表中出现的次数. 语法 count() 方法语法: L.count(obj) 参数 obj -- 列表中统计的对象. 返回值 返回元素 ...

  8. Python cos() 函数

    描述 cos() 返回x的弧度的余弦值. 语法 以下是 cos() 方法的语法: import math math.cos(x) 注意:cos()是不能直接访问的,需要导入 math 模块,然后通过 ...

  9. Aixs2 使用总结,持续更新中 ...

    参考博客:http://zhangjunhd.blog.51cto.com/113473/23692     消息交换模式. 目前Axis2支持三种模式:In-Only.Robust-In和In-Ou ...

  10. powerdesigner学习笔记【转载】

    转自:http://blog.itpub.net/11968859/viewspace-620440/ 谢谢! 1.做CDM模型的时候,因为开始定义ITEM的时候,没有注意把NAME和CODE全定义成 ...