Redis Log System

Source: Internet
Author: User
What is slowlog?

Slow log is the log system used by redis to record the query execution time.

The query execution time does not include I/O operations such as client response (TALKING) and reply sending, but is the time consumed by executing a query command.

In addition, the slow log is stored in the memory, and the read/write speed is very fast. Therefore, you can use it with confidence and do not have to worry about compromising the redis speed because slow log is enabled.


Set slowlog

The slow log behavior is specified by two configuration parameters (configuration parameter). You can rewrite the redis. conf file or useConfigAndConfigCommand to modify them dynamically.

The first option isSlowlog-log-slower-thenIt determines how many microseconds (microsecond, 1 second = 1,000,000 microseconds) the execution time is greater.

For example, execute the following command to record all queries whose query time is greater than or equal to 100 microseconds:

Config slowlog-log-slower-then,

The following command records all queries with a query time greater than 1000 microseconds:

Config slowlog-log-slower-then.

Another option isSlowlog-max-LenIt determines the maximum number of logs that slow log can store. Slow log is a LIFO queue. When the queue size exceedsSlowlog-max-LenThe oldest log is deleted, and the newest log is added to the slow log, and so on.

Run the following command to allow slow logs to store a maximum of 1000 logs:

Config slowlog-max-Len.

UseConfigCommand to query the current values of the two options:

redis> CONFIG GET slowlog-log-slower-than1) "slowlog-log-slower-than"2) "1000"redis> CONFIG GET slowlog-max-len1) "slowlog-max-len"2) "1000"

View slow log

To view the slow log, you can useSlowlogOrSlowlog numberCommand, the former prints all slow logs, the maximum length depends onSlowlog-max-LenOption value, whileSlowlog numberOnly a specified number of logs are printed.

The latest logs will be printed first:

Redis> slowlog get1) 1) (integer) 12 # log identifier of the unique (unique) 2) (integer) 1324097834 # execution time of the recorded command, expressed in UNIX timestamp Format 3) (integer) 16 # query execution time, in microseconds (Unit 4) 1) "Config" # Run the command in array Format 2) "get" # The complete command here is config get slowlog-log-slower-than 3) "slowlog-log-slower-than" 2) 1) (integer) 11 2) (integer) 1324097825 3) (integer) 42 4) 1) "Config" 2) "get" 3) "*" 3) 1) (integer) 10 2) (integer) 1324097820 3) (integer) 11 4) 1) "Config" 2) "get" 3) "slowlog-log-slower-then "#...

The unique log ID is reset only when the redis server is restarted, this avoids repeated processing of logs (for example, you may want to send an email to you every time you find a new slow query ).

View the number of current logs

Use commandsSlowlogYou can view the number of current logs.

Please note that this value andSlower-max-LenThe difference is that one is the current number of logs, and the other is the maximum number of logs allowed to be recorded.

redis> SLOWLOG LEN(integer) 14


Clear logs

Use commandsSlowlog ResetSlow log can be cleared.

redis> SLOWLOG LEN(integer) 14redis> SLOWLOG RESETOKredis> SLOWLOG LEN(integer) 0


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.