SLOWLOG GET
SLOWLOG GET [count]
- Available since:
- Redis Open Source 2.2.12
- Time complexity:
- O(N) where N is the number of entries returned
- ACL categories:
-
@admin,@slow,@dangerous, - Compatibility:
- Redis Software and Redis Cloud compatibility
The SLOWLOG GET command returns entries from the slow log in chronological order.
The Redis Slow Log is a system to log queries that exceeded a specified execution time. The execution time does not include I/O operations like talking with the client, sending the reply and so forth, but just the time needed to actually execute the command (this is the only stage of command execution where the thread is blocked and can not serve other requests in the meantime).
A new entry is added to the slow log whenever a command exceeds the execution time threshold defined by the slowlog-log-slower-than configuration directive.
The maximum number of entries in the slow log is governed by the slowlog-max-len configuration directive.
By default the command returns latest ten entries in the log. The optional count argument limits the number of returned entries, so the command returns at most up to count entries, the special number -1 means return all entries.
Each entry from the slow log is comprised of the following seven values:
- A unique progressive identifier for every slow log entry.
- The unix timestamp at which the logged command was processed.
- The amount of time needed for its execution, in microseconds.
- The array composing the arguments of the command.
- Client IP address and port.
- Client name if set via the
CLIENT SETNAMEcommand. - The total number of arguments in the command, including the command name. Added in Redis 8.10.
The logged argument array (value 4) is truncated when the command has more arguments than the slowlog-max-argc configuration directive allows (32 by default). In that case, the last logged element is replaced with a string of the form ... (N more arguments). The total argument count (value 7) always reflects the command's original argument count, captured before truncation, so it can be read directly without parsing that string.
The entry's unique ID can be used in order to avoid processing slow log entries multiple times (for instance you may have a script sending you an email alert for every new slow log entry). The ID is never reset in the course of the Redis server execution, only a server restart will reset it.
Optional arguments
count
The number of recent slow-log entries to return. -1 returns all entries; the default is 10.
Examples
The seventh element of each entry reports the command's total argument count. This is most useful for variadic commands whose logged argument list has been truncated. In the following example, the slowlog-max-argc limit is left at its default of 32 and a SADD command is issued with 33 arguments (the command name, the key, and 31 members):
redis> CONFIG SET slowlog-log-slower-than 0
OK
redis> SLOWLOG RESET
OK
redis> SADD myset 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
(integer) 31
redis> SLOWLOG GET 1
1) 1) (integer) 12
2) (integer) 1752422400
3) (integer) 21
4) 1) "SADD"
2) "myset"
3) "3"
4) "4"
...
32) "... (2 more arguments)"
5) "127.0.0.1:52276"
6) ""
7) (integer) 33
The logged argument array (element 4) is truncated to 32 items, with the final item indicating how many more arguments were omitted. The argument count (element 7) still reports the original total of 33.
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ✅ Standard |
✅ Standard |
Not supported for scripts. Also, the client IP address, port, and name are not returned by Redis Software. |
Return information
History
- Starting with Redis version 4.0.0: Added client IP address, port and name to the reply.
- Starting with Redis version 8.10.0: Added original command argument count to the reply.