Database Reference
In-Depth Information
A Multi-Resolution Redis Client
Redis works particularly well with multi-resolution aggregation. Its
high performance and large variety of data types make it easy to
implement complicated data environments in relatively short order. A
multi-resolution aggregation Redis client begins with an aggregator and
a standard Redis connection. This example uses the Redis client, but
any Java Redis client should work:
public class
RedisClient
implements
Expirer {
Jedis jedis;
public
RedisClient jedis(Jedis jedis) {
this
.jedis = jedis;
return this
;
}
Aggregator aggregator;
public
RedisClient aggregator(Aggregator
aggregator) {
this
.aggregator = aggregator;
aggregator.expirer(
this
);
return this
;
}
Redis supports expiration, so this client implements the
Expirer
interface to allow aggregates to age out (for example, five-minute
aggregates after two days, hourly aggregates after a week, and so on).
This interface has a single method that is called on every top-level key:
public void
expire(String key,
long
retainMillis) {
jedis.expire(key, (
int
)(retainMillis/1000));
}
It doesn't make sense to implement the multi-resolution getter
methods, but the primary setter methods—
incrby
,
hincrby
,
zincrby
, and
sadd
—are all good candidates for multi-resolution