Table of contents
The difference between Pipeline and transaction
Calling Redis commands in Lua scripts
Using Redis+Lua language to implement current limiting
Redis slow query
Many storage systems (such as MySQL) provide slow query logs to help development and operation and maintenance personnel locate slow operations in the system. The so-called slow query log means that the system calculates the execution time of each command before and after the command is executed. When it exceeds the preset threshold, the relevant information of this command (such as: occurrence time, time consumption, detailed information of the command) is recorded. Redis also provides similar functionality.
A command executed by the Redis client is divided into the following four parts:
1. Send command
2. Command queuing
3. Command execution
4. Return results
It should be noted that slow query only counts the time in step 3, so the absence of slow query does not mean that the client does not have timeout problems. Because there may be a network problem with the command or the command is queued in Redis, it does not mean that the command execution is slow or that it is a slow query, but it may be a network problem or the Redis service is very busy (long queue wait).
Slow query configuration
For any slow query function, two things need to be clarified: how slow is considered slow, that is, how to set the preset threshold? Where are slow query records stored?
Redis provides two ways to configure slow queries
1. Dynamic settings
The default threshold for slow queries is 10 milliseconds
Parameters: slowlog-log-slower-than is the time preset threshold. Its unit is microseconds (1 second = 1000 milliseconds = 1 000 000 microseconds). The default value is 10 000. If a "very slow" is executed A command (such as keys *), if its execution time exceeds 10,000 microseconds, which is 10 milliseconds, then it will be recorded in the slow query log.
We modify it through dynamic commands
--javascripttypescriptbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
config set slowlog-log-slower-than 20000
After using config set, if you want to persist the configuration to Redis.conf, you need to execute config rewrite
--javascripttypescriptbashsqljsonhtmlcssccppjavarubypythongorustmarkdown
config rewrite
Notice:
If slowlog-log-slower-than=0 is configured, all commands will be logged, and slowlog-log-slower-than<0 will not log any commands.
2. Configuration file settings (the service needs to be restarted after modification to take effect)
Open the Redis configuration file redis.conf, and you can see the following configuration: