建立在redis之上的timeseries api
redis-timeseries的Python项目详细描述
redis时间序列
建立在redis之上的时间序列api,可用于存储和查询 时间序列统计。可以使用多次粒度来保持 不同时间间隔的轨迹。
- 自由软件:麻省理工学院许可证
- 文档:https://redis-timeseries.readthedocs.io。
安装
要安装redis timeseries,请在终端中运行此命令:
$ pip install redis_timeseries
使用量
若要初始化TimeSeries类,必须将redis客户端传递给 访问数据库。您还可以覆盖时间序列的基键。
>>> import redis >>> client = redis.StrictRedis() >>> ts = TimeSeries(client, base_key='my_timeseries')
要自定义粒度,请确保每个粒度都有一个ttl 和duration秒。您可以使用helper函数 更容易定义。
>>> my_granularities = { ... '1minute': {'ttl': hours(1), 'duration': minutes(1)}, ... '1hour': {'ttl': days(7), 'duration': hours(1)} ... } >>> ts = TimeSeries(client, granularities=my_granularities)
.record_hit()接受键和可选的时间戳和增量 数一数。它将以所有定义的粒度记录数据。
>>> ts.record_hit('event:123') >>> ts.record_hit('event:123', datetime(2017, 1, 1, 13, 5)) >>> ts.record_hit('event:123', count=5)
.record_hit()将在execute=True时自动执行。如果你 设置execute=False,可以将命令链接到单个redis中 管道。然后必须使用.execute()执行管道。
>>> ts.record_hit('event:123', execute=False) >>> ts.record_hit('enter:123', execute=False) >>> ts.record_hit('exit:123', execute=False) >>> ts.execute()
.get_hits()将在数据库中查询 选定的粒度。如果要查询最后3分钟,则 将查询计数为3的1minute粒度。这会回来的 元组列表(bucket, count),其中bucket是舍入的时间戳。
>>> ts.get_hits('event:123', '1minute', 3) [(datetime(2017, 1, 1, 13, 5), 1), (datetime(2017, 1, 1, 13, 6), 0), (datetime(2017, 1, 1, 13, 7), 3)]
.get_total_hits()将查询数据库并只返回所有 查询中的存储桶。
>>> ts.get_total_hits('event:123', '1minute', 3) 4
^ tt12}$将返回可能存在于 选定范围。可以传递搜索字符串来限制返回的键。 搜索字符串应该始终有一个*来定义通配符。
>>> ts.scan_keys('1minute', 10, 'event:*') ['event:123', 'event:456']
功能
- 多粒度跟踪
- redis管道链接
- 钥匙扫描仪
- 易于与图表软件包集成
- 可以选择整数或浮点计数
- 支持时区的日期标记
历史记录
0.1.8(2017-07-25)
- 修复@round@time()方法中的错误
0.1.7(2017-07-25)
- 修复@round@time()方法中的错误
0.1.6(2017-07-25)
- 添加时区,以便日存储桶将在正确时区的午夜开始
0.1.5(2017-07-18)
- 更新默认粒度
0.1.4(2017-07-12)
- 增加浮点值功能
- add increase()和decrease()方法
- 移动get_hits()->;get_bucket()和get_total_hits()->;get_total()
0.1.3(2017-03-30)
- 取出六个包裹
- 清除源文件
0.1.2(2017-03-30)
- 使python 3兼容
- 修正毒素使pypy工作
0.1.1(2017-03-30)
- 次要项目文件更新
0.1.0(2017-03-30)
- pypi上的第一个版本。