bellycard/redistat — pull request #18 by joedivita (2014-01-23 22:31:34+00:00)
Title: Adding support for unique counters

Adding support for Unique Counters

Unique counters are used when an event with the same unique_id should not be counted twice. A general example of this could be a counter for the number of users that visited a place. In this case the "id" parameter would represent the id of the place and the unique_id would be the users id.

Unique counters utilize Redis bitmaps and although their api is the same as regular counters, their implementations of the same methods are slightly different.

This pull request enables the following:

Incrementing / Decrementing (which essentially just adds the unique id to the set for that particular id / time):
``` ruby
Customers.increment(id: 1, timestamp: '2014-01-05', unique_id: 1000)
Customers.increment(id: 1, timestamp: '2014-01-05', unique_id: 1001)
```

Find:
``` ruby
Customers.find(id: 1, year: 2014, month: 1, day: 5, unique_id: 1000) # Returns true or false
```

Find the aggregate total over a datespan (this would only return the **unique** aggregate total):
``` ruby
Customers.aggregate(id: 1, start_date: '2014-01-01', end_date: '2014-01-05')
```

Find the aggregate total + data points for each point at a specified interval (again, this returns not only the **unique** aggregate total, but also the unique total for each interval data point ~ being each day / week / month / year...etc)
``` ruby
Customers.aggregate(id: 1, start_date: '2014-01-01', end_date: '2014-01-05', interval: :days)
```

All of these methods also support mutiple ids. For example, we can find the unique aggregate totals across multiple ids by doing:
``` ruby
Customers.aggregate(id: [1,2,3], start_date: '2014-01-01', end_date: '2014-01-05', interval: :days)
```