Skip to content

Instantly share code, notes, and snippets.

@prisoner
Last active December 20, 2015 19:09
Show Gist options
  • Save prisoner/6180999 to your computer and use it in GitHub Desktop.
Save prisoner/6180999 to your computer and use it in GitHub Desktop.
Fast, easy, realtime metrics using Redis bitmaps
import redis.clients.jedis.Jedis;
import java.util.BitSet;
Jedis redis = new Jedis("localhost");
public int uniqueCount(String action, String date) {
String key = action + ":" + date;
BitSet users = BitSet.valueOf(redis.get(key.getBytes()));
return users.cardinality();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment