EBOOK – REDIS IN ACTION

This book covers the use of Redis, an in-memory database/data structure server.

open all | close all

5.2 Counters and statistics

As you saw way back in chapter 2 when I introduced the concept of counting individual
page visits, having basic hit count information can (for example) change the way
we choose our caches. But our example from chapter 2 was very simple, and reality is
rarely that simple, especially when it involves a real website.

The fact that our site received 10,000 hits in the last 5 minutes, or that the database
handled 200 writes and 600 reads in the last 5 seconds, is useful information to know.
If we add the ability to see that information over time, we can notice sudden or gradual
increases in traffic, predict when server upgrades are necessary, and ultimately
save ourselves from downtime due to an overloaded system.

This section will work through two different methods for recording both counters
and statistics in Redis, and will finish by discussing how to simplify the collection of
our example statistics. Both of these examples are driven by real use cases and requirements.
Our next stop on the road of application introspection is collecting time series
counters in Redis.