Home  >  Article  >  Database  >  What is the use of slowlog in Redis?

What is the use of slowlog in Redis?

PHPz
PHPzforward
2023-05-29 17:29:211117browse

Redis uses slowlog to record the query execution time logging system. Note that this query execution time does not include IO operations such as client response (talking) and sending replies, but only the time spent executing a query command.

What is the use of slowlog in Redis?

slowlog is stored in memory and has very fast read and write speeds, so we can use it with confidence without worrying about damaging the speed of Redis by turning on slowlog.

slowlog has two important configurations. We first use the CONFIG GET slowlog-* command to view the existing configuration.

What is the use of slowlog in Redis?

slowlog-log-slower-than indicates the threshold for slow queries, in microseconds. If the execution time of a query command exceeds the set limit threshold, the command will be recorded in the slow query log. Log all commands when slowlog-log-slower-than=0. When the value of slowlog-log-slower-than is less than or equal to 0, no commands will be logged. The default value for slowlog-log-slower-than is 10000 (10 milliseconds, 1 second = 1,000 milliseconds = 1,000,000 microseconds).

slowlog-max-len represents the maximum number of slow query logs. This is a first-in-first-out queue storage structure. When the number of slow query log entries reaches the upper limit, the oldest recorded log entry will be destroyed. The default value of slowlog-max-len is 128, which is stored in memory, so restarting redis will clear the slow query log.

The commands to configure slowlog-log-slower-than and slowlog-max-len are very simple, as follows:

What is the use of slowlog in Redis?

##Use the SLOWLOG LEN command to query the current The number of slow query log records.

What is the use of slowlog in Redis?

When we only need to query the first few slow query records, we can use the SLOWLOG GET [n] command.

What is the use of slowlog in Redis?

SLOWLOG GET [n] If n is not added, all slow query records will be obtained.

Clear the slow query log using SLOWLOG RESET. Please be careful not to set slowlog-log-slower-than too large, as too large a setting may result in no records being logged.

The above is the detailed content of What is the use of slowlog in Redis?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete