slowlog get command supports passing in -1 to get all logs. (#9018)
This was already the case before this commit, but it wasn't clear / intended in the code, now it does.
This commit is contained in:
parent
dee378d76d
commit
7900b48bc7
@ -143,8 +143,8 @@ void slowlogCommand(client *c) {
|
||||
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) {
|
||||
const char *help[] = {
|
||||
"GET [<count>]",
|
||||
" Return top <count> entries from the slowlog (default: 10). Entries are",
|
||||
" made of:",
|
||||
" Return top <count> entries from the slowlog (default: 10, -1 mean all).",
|
||||
" Entries are made of:",
|
||||
" id, timestamp, time in microseconds, arguments array, client IP and port,",
|
||||
" client name",
|
||||
"LEN",
|
||||
@ -168,9 +168,18 @@ NULL
|
||||
listNode *ln;
|
||||
slowlogEntry *se;
|
||||
|
||||
if (c->argc == 3 &&
|
||||
getLongFromObjectOrReply(c,c->argv[2],&count,NULL) != C_OK)
|
||||
return;
|
||||
if (c->argc == 3) {
|
||||
/* Consume count arg. */
|
||||
if (getRangeLongFromObjectOrReply(c, c->argv[2], -1,
|
||||
LONG_MAX, &count, "count should be greater than or equal to -1") != C_OK)
|
||||
return;
|
||||
|
||||
if (count == -1) {
|
||||
/* We treat -1 as a special value, which means to get all slow logs.
|
||||
* Simply set count to the length of server.slowlog.*/
|
||||
count = listLength(server.slowlog);
|
||||
}
|
||||
}
|
||||
|
||||
listRewind(server.slowlog,&li);
|
||||
totentries = addReplyDeferredLen(c);
|
||||
|
@ -175,4 +175,26 @@ start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
|
||||
r debug sleep 0.2
|
||||
assert_equal [r slowlog len] 0
|
||||
} {} {needs:debug}
|
||||
}
|
||||
|
||||
test {SLOWLOG - count must be >= -1} {
|
||||
assert_error "ERR count should be greater than or equal to -1" {r slowlog get -2}
|
||||
assert_error "ERR count should be greater than or equal to -1" {r slowlog get -222}
|
||||
}
|
||||
|
||||
test {SLOWLOG - get all slow logs} {
|
||||
r config set slowlog-log-slower-than 0
|
||||
r config set slowlog-max-len 3
|
||||
r slowlog reset
|
||||
|
||||
r set key test
|
||||
r sadd set a b c
|
||||
r incr num
|
||||
r lpush list a
|
||||
|
||||
assert_equal [r slowlog len] 3
|
||||
assert_equal 0 [llength [r slowlog get 0]]
|
||||
assert_equal 1 [llength [r slowlog get 1]]
|
||||
assert_equal 3 [llength [r slowlog get -1]]
|
||||
assert_equal 3 [llength [r slowlog get 3]]
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user