rts
Use redis as time series data store.
- Data for the line chart of a period time, can be use to stat sum/avg/max/min/count of a behavior.
e.g. Every 5 minutes, sum of user click of the website.
e.g. Every Day, average consume money of the website.
- Aggregate data of DayOfWeek or HoursOfDay, to analytisic behavior.
e.g. The sum of click from Monday to SunDay.
Init
var rts = require('rts')(options);
var rts = require('rts')({
redis: redis,
gran: '5m, 1h, 1d, 1w',
points: 500,
prefix: ''
});
Options:
redis
the redis clientgran
granularity of recored time. Format is '{number}{unit}, {number}{unit}...'. The unit can bes
second,m
minute,h
hour,d
day,w
week,M
month,y
year. e.g.5m, 1h
, store data for 5 mintues and 1 hour.points
how many data will be keep. We care about recentlyn
points of data for each granularity. Think about1s
data, if store 1 day data, it is 86400 rows data, we should reduce it to5m
data, it is only 288 rows. We just care small granularity data for recently, for the history, we just care large granualrity, like revenue of2010-11
, not revenue of2010-11-05 12 o'clock
.prefix
the redis key prefix.
Record
record(behavior, [behaviorValue], [statistics], [aggregations])
behavior
behaviorValue
statistics
: Array of statistic type, avariable member ofsum
,count
,avg
,max
,min
. default [sum
].aggragations
hm
hour of day, splite data every monthhq
hour of day, splite data every seasonhy
hour of day, splite data every yeardm
day of week, splite data every month.dq
day of week, splite data every seasondy
day of week, splite data every year
ts // recore a clickts // recored behavior with value, and aggragation. ts
Query
ts.getStat(statistic, behavior, granularity, fromDate, toDate, callback)
ts[statistic](behavior, granularity, fromDate, toDate, callback)
ts.aggr{statistic}(behavior, aggragation, date, callback)
statistic
sum
,avg
,count
,max
,min
. Must be a member when statistics whenrecord
!behavior
granularity
The time unit, seeOptions
, Must be a part ofoptions.gran
fromDate
toDate
tststststs ts