![multi counter on stream multi counter on stream](https://i.ytimg.com/vi/btMdKZ90tpk/maxresdefault.jpg)
Instead, we’ll use a ZSET, where the members are the combinations of precisions and names that have been written to, and the scores are all 0. We could use a LIST combined with a SET, but that would take extra code and round trips to Redis.
![multi counter on stream multi counter on stream](https://i5.walmartimages.com/asr/a7f82c05-41e5-4a48-8fad-9bc38e9f0fe3.ff3d86c7dea2c71c29f297eb23058f50.jpeg)
For this, we need an ordered sequence that lets us iterate one by one over its entries, and that also doesn’t allow duplicates.
![multi counter on stream multi counter on stream](http://ecx.images-amazon.com/images/I/41gVvLFEnrL.jpg)
Figure 5.1 shows a selection of data from a hit counter with 5-second time slices.Īs we start to use counters, we need to record what counters have been written to so that we can clear out old data. The keys in the hash will be the start of the time slice, and the value will be the number of hits. For each counter and precision, like site hits and 5 seconds, we’ll keep a HASH that stores information about the number of site hits that have occurred in each 5-second time slice.
#Multi counter on stream update#
In order to update counters, we’ll need to store the actual counter information. The first step for keeping counters is actually storing the counters themselves. Both the number of samples and the selection of precisions to record can be customized as necessary. Each of these counters will store the most recent 120 samples at a variety of time precisions (like 1 second, 5 seconds, 1 minute, and so on). In an attempt to start gathering metrics to watch and analyze, we’ll build a tool to keep named counters over time (counters with names like site hits, sales, or database queries can be crucial). But if we aren’t recording any metrics, then it’s impossible to know how they’re changing, or whether we’re doing better or worse. Subsequently, any number of other performance metrics may change. Code changes (that can affect how quickly our site responds, and subsequently how many pages we serve), new advertising campaigns, or new users to our system can all radically change the number of pages that are loaded on a site. As we monitor our application, being able to gather information over time becomes ever more important.