antirez/redis — pull request #231 by mrb (2011-12-04 02:26:49+00:00)
Title: Range option for slowlog get

Decided to hack this in for my weekend project. Went pretty quickly! This is a proposal for an optional 3rd parameter to SLOWLOG. This would leave the slowlog API looking like this:

* slowlog len - returns length of slowlog list
* slowlog reset - resets slowlog
* slowlog get n - gets all members of slowlog from 0 - n
* slowlog get n p - gets all members of slowlog from n - p

I added the fourth, which turns the 2nd parameter into the beginning and the 3rd parameter into the end of a range of slowlog queries to return. This will be very helpful in assembling UIs for slowlog queries (i.e. for pagination).

Since the slowlog is a list in memory, I'm not that concerned with it's relatively naive implementation (naive in this case because it rewinds the slowlog list, iterates to the beginning of the range, and then ouputs the rest). This is a safer, easier way to add this feature, because it means not having to change the slowlog data structure or much about the code at all.

I also added some simple tests.

Note: the GET right now returns an exclusive range, e.g. SLOWLOG GET 1 3 returns 1 and 2 - 2 entries.