bitmapist: Powerful realtime analytics with Redis

WBOY
풀어 주다: 2016-06-07 16:28:13
원래의
1142명이 탐색했습니다.

I just released bitmapist (GitHub) - a powerful realtime analytics library that can help you answer following questions: Has user 123 been online today? This week? This month? Has user 123 performed action "X"? How many users have been act

Redis logo

I just released bitmapist (GitHub) - a powerful realtime analytics library that can help you answer following questions:

  • Has user 123 been online today? This week? This month?
  • Has user 123 performed action "X"?
  • How many users have been active have this month? This hour?
  • How many unique users have performed action "X" 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?

This library is very easy to use and enables you to create your own reports easily.

Using Redis bitmaps you can store events for millions of users in a very little amount of memory (megabytes). You should be careful about using huge ids (e.g. 2^32 or bigger) as this could require larger amounts of memory.

If you want to read more about bitmaps please read following:

  • Fast, easy, realtime metrics using Redis bitmaps
  • Redis setbit
  • Wikipedia: Bit Array
  • Crashlytics on Redis Analytics

Requires Redis 2.6+ and newest version of redis-py.

Installation

sudo pip install bitmapist
로그인 후 복사

Examples

Setting things up:

from datetime import datetime, timedelta
from bitmapist import setup_redis, delete_all_events, mark_event,\
                      MonthEvents, WeekEvents, DayEvents, HourEvents,\
                      BitOpAnd, BitOpOr
now = datetime.utcnow()
last_month = datetime.utcnow() - timedelta(days=30)
로그인 후 복사

Mark user 123 as active and has played a song:

mark_event('active', 123)
mark_event('song:played', 123)
로그인 후 복사

Answer if user 123 has been active this month:

assert 123 in MonthEvents('active', now.year, now.month)
assert 123 in MonthEvents('song:played', now.year, now.month)
로그인 후 복사

How many users have been active this week?

print len(WeekEvents('active', now.year, now.isocalendar()[1]))
로그인 후 복사

Perform bit operations. How many users that have been active last month are still active this month?

active_2_months = BitOpAnd(
    MonthEvents('active', last_month.year, last_month.month),
    MonthEvents('active', now.year, now.month)
)
print len(active_2_months)
# Is 123 active for 2 months?
assert 123 in active_2_months
로그인 후 복사

Work with nested bit operations (imagine what you can do with this ;-))!

active_2_months = BitOpAnd(
    BitOpAnd(
        MonthEvents('active', last_month.year, last_month.month),
        MonthEvents('active', now.year, now.month)
    ),
    MonthEvents('active', now.year, now.month)
)
print len(active_2_months)
assert 123 in active_2_months
로그인 후 복사
bitmapist: Powerful realtime analytics with Redis
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿