jithujose/bitter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jithujose/bitter

Composer 安装命令:

composer require jithujose/bitter

包简介

Bitter is a simple but powerful analytics library

README 文档

README

https://secure.travis-ci.org/jeremyFreeAgent/Bitter.png?branch=master

1.2.0 WORK IN PROGRESS

Bitter is a simple but powerful analytics library

"Use Bitter and you have time to drink a bitter beer !"

-- Jérémy Romey

Bitter can answer following questions:

  • Has user X been online today? This week? This month?
  • Has user X performed action "Y"?
  • How many users have been active have this month? This hour?
  • How many unique users have performed action "Y" this week?
  • How many % of users that were active last week are still active?
  • How many % of users that were active last month are still active this month?

Bitter is very easy to use and enables you to create your own reports easily - see the Bitter Library website for more info and documentation about this project.

Installation

Use Composer to install: free-agent/bitter.

In your composer.json you should have:

{
    "require": {
        "free-agent/bitter": "1.1.*"
    }
}

Requirements

Bitter uses Redis with version >=2.6.

Note: Every key created in Redis will be prefixed by bitter:, temp keys by bitter_temp:.

Bitter uses Bitset PECL extension with version =1.0.1 for the getIds method.

Basic usage

Create a Bitter with a Redis client (Predis as example):

$redisClient = new \Predis\Client();
$bitter = new \FreeAgent\Bitter\Bitter($redisClient);

Mark user 123 as active and has played a song:

$bitter
    ->mark('active', 123)
    ->mark('song:played', 123)
;

Note: Please don't use huge ids (e.g. 2^32 or bigger) cause this will require large amounts of memory.

Pass a DateTime as third argument:

$bitter->mark('song:played', 123, new \DateTime('yesterday'));

Test if user 123 has played a song this week:

$currentWeek = new FreeAgent\Bitter\UnitOfTime\Week('song:played');

if ($bitter->in(123, $currentWeek) {
    echo 'User with id 123 has played a song this week.';
} else {
    echo 'User with id 123 has not played a song this week.';
}

How many users were active yesterday:

$yesterday = new \FreeAgent\Bitter\UnitOfTime\Day('active', new \DateTime('yesterday'));

echo $bitter->count($yesterday) . ' users were active yesterday.';

Using BitOp

How many users that were active yesterday are also active today:

$today     = new \FreeAgent\Bitter\UnitOfTime\Day('active');
$yesterday = new \FreeAgent\Bitter\UnitOfTime\Day('active', new \DateTime('yesterday'));

$count = $bitter
    ->bitOpAnd('bit_op_example', $today, $yesterday)
    ->count('bit_op_example')
;
echo $count . ' users were active yesterday and today.';

Note: The bit_op_example key will expire after 60 seconds.

Test if user 123 was active yesterday and is active today:

$today     = new \FreeAgent\Bitter\UnitOfTime\Day('active');
$yesterday = new \FreeAgent\Bitter\UnitOfTime\Day('active', new \DateTime('yesterday'));

$active = $bitter
    ->bitOpAnd('bit_op_example', $today, $yesterday)
    ->in(123, 'bit_op_example')
;
if ($active) {
    echo 'User with id 123 was active yesterday and today.';
} else {
    echo 'User with id 123 was not active yesterday and today.';
}

Note: Please look at Redis BITOP Command for performance considerations.

Custom date period stats

How many users that were active during a given date period:

$from = new \DateTime('2010-14-02 20:15:30');
$to   = new \DateTime('2012-21-12 13:30:45');

$count = $bitter
    ->bitDateRange('active', 'active_period_example', $from, $to)
    ->count('active_period_example')
;
echo $count . ' users were active from "2010-14-02 20:15:30" to "2012-21-12 13:30:45".';

Get Ids for a given key

Get Ids for a given date period:

$from = new \DateTime('2010-14-02 20:15:30');
$to   = new \DateTime('2012-21-12 13:30:45');

$ids = $bitter
    ->bitDateRange('active', 'active_period_example', $from, $to)
    ->getIds('active_period_example')
;
echo 'Ids of users that were active from "2010-14-02 20:15:30" to "2012-21-12 13:30:45":';
echo '<br />';
echo implode(', ', $ids);

Unit Tests

You can run tests with:

bin/atoum -d tests/units

Release notes

1.2.0

  • Added a remove method to remove a specific temp key.
  • Added a removeEvent method to remove all data of an event.
  • Renamed Event to UnitOfTime in order to be more explicit.

1.1.0

  • Added date period stats with bitDateRange method.

Todo

Thanks

This library is a port of bitmapist (Python) by Amir Salihefendic.

jithujose/bitter 适用场景与选型建议

jithujose/bitter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「redis」 「analytics」 「bitter」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jithujose/bitter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jithujose/bitter 我们能提供哪些服务?
定制开发 / 二次开发

基于 jithujose/bitter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-05-18