Skip to content

splitice/redis

 
 

Repository files navigation

Time Average Datastructure for Redis.

This data structure provides the ability to efficiently produce an average rate of events, and distinct events occuring over a set time frame. This value can then be divided over time to produce an average rate.

  • "ta*" commands track the occurance of events over time
  • "tu*" commands track unique events happening over time

Event Commands:

tahit [interval] [by] [timestamp] [key1] [key2...]

Signal that the event has happened, increment each [key] by the the value of [by] within the scope of [timestamp].

Returns the new sum over time value for each key (bulk reply) based on the current [timestamp]. The [interval] between buckets (how much time does a bucket represent) must be provided for this calculation.

tacalc [interval] [timestamp] [key]

Returns the sum over time value for a given key based on the current [timestamp]. The [interval] between buckets (how much time does a bucket represent) must be provided for this calculation.

Unique Event Commands:

tuhit [interval] [unique value] [timestamp] [key1] [key2...]

Signal that the event has happened, with the [unique value]. Increment each [key] if the [unique value] is unique within the scope of [timestamp].

Returns the new sum over time value for each key (bulk reply) based on the current [timestamp]. The [interval] between buckets (how much time does a bucket represent) must be provided for this calculation.

tuupdate [interval] [unique values] [timestamp] [key1] [key2...]

Signal that the event has happened, with the each value in [unique values]. Increment each [key] if the unique value is unique within the scope of [timestamp]. A unique value is extracted from [unique values]. [unique values] is split by the 0x00 (\x00) character. This function is not binary safe for [unique values].

Returns OK if successful.

tucalc [interval] [timestamp] [key]

Returns the sum of unqiue events over time value for a given key based on the current [timestamp]. The [interval] between buckets (how much time does a bucket represent) must be provided for this calculation.

Also returns the time this structure was reated

Data Structure:

The number of buckets is detimrined by a compile time constants.

  • TA_BUCKETS defaults to 20
  • TU_BUCKETS defaults to 6

Time Average

 ---------------------------------------------
 |               |         |         |
 |  Last Updated | Bucket0 | Bucket1 | ....
 |     32bit     |  32bit  |  32bit  |
 |               |         |         |
 ---------------------------------------------

Time Unique Average

 ------------------------------------------------------------
 |               |              |         |         |
 |  Last Updated | Time Created | Bucket0 | Bucket1 | ....
 |     32bit     |     32bit    |   HLL   |   HLL   |
 |               |              |         |         |
 ------------------------------------------------------------

Memory Requirements

  • Time average objects require 84 bytes of memory per object.
  • Time unique average objects require UP TO 73Kb of memory per object.

About

Redis fork adding support for additional data structures.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 79.6%
  • Tcl 16.8%
  • Ruby 2.7%
  • Shell 0.5%
  • Makefile 0.3%
  • C++ 0.1%