Redis Common management Commands

Source: Internet
Author: User
Tags redis unique id redis server
Redis Common management commands:

bgrewriteaof

Asynchronously (asynchronously) rewrites the AoF file to reflect the state of the current database.

Even if the bgrewriteaof command fails, the data in the old aof file will not be lost or changed. Bgsave

Asynchronously saves data from the current database to disk in the background.

The Bgsave command returns OK immediately after execution, then Redis fork out a new subprocess, the original Redis process (the parent process) continues to process the client request, and the child process is responsible for saving the data to disk and then exiting.

The client can view the relevant information through the Lastsave command to determine whether the Bgsave command was executed successfully.  

SAVE

Synchronizes the data from the current database to disk.  

Lastsave

Returns the point of time (save, Bgsave, etc.) that the last Redis successfully performed a save operation, expressed in UNIX timestamp format.  

dbsize

Returns the number of key keys for the current database.

slaveof

Slaveof Host Port

The slaveof command is used to dynamically modify the replication (replication) functionality while the Redis is running.

By executing the slaveof host Port command, you can convert the current server to a secondary server (slave server) for the specified server.

If the current server is already a secondary server for a primary server (master server), executing slaveof host port will cause the current server to stop synchronizing the old primary server, discard the old dataset, and start synchronizing the new primary server.

In addition, executing a command on a subordinate server, Slaveof no one, will enable the secondary server to turn off replication and transform it from the subordinate server back to the primary server, and the data set originally synchronized will not be discarded.

With the feature "Slaveofnoone does not discard the synchronized data set", the secondary server can be used as the new primary server when the primary server fails, enabling uninterrupted operation.  

Flushall

Clears the entire Redis server's data (deletes all keys for all databases).

This command never fails.  

Flushdb

Clears all key in the current database.

This command never fails.

 

SHUTDOWN

The shutdown command performs the following actions: Stop all clients if there is at least one savepoint waiting, execute the Save command if the AOF option is turned on, update the AOF file server shutdown

If persistence is turned on, the SHUTDOWN command ensures that the server shuts down properly without losing any data.

If you simply execute the Save command and then execute the QUIT command, then there is no guarantee-because the other clients may be communicating with the server after the save is executed and the time before the QUIT, if the execution of the QUIT results in a loss of data.

Slowlog

SLOWLOG subcommand [argument]

What is Slowlog

Slow log is a log system used by Redis to record query execution time.

Query execution time refers to not including IO operations such as client response (talking), sending replies, and so on, but simply the time spent executing a query command.

In addition, slow log is stored in memory, read and write very fast, so you can use it safely, do not have to worry because of the opening slow log and damage Redis speed.

Set Slowlog

The behavior of the slow log is specified by two configuration parameters (configuration parameter) that can be modified dynamically by overwriting redis.conf files or using the config Get and config SET commands.

The first option is Slowlog-log-slower-then, which determines whether to record queries that have an execution time greater than microseconds (microsecond,1 seconds = 1,000,000 microseconds).

For example, executing the following command will allow slow log to record all queries with a query time greater than or equal to 100 microseconds:

CONFIG SET Slowlog-log-slower-then 100,

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

CONFIG SET Slowlog-log-slower-then 1000.

Another option is Slowlog-max-len, which determines how many logs slow log can hold, slow log itself is a LIFO queue, the oldest log will be deleted when the queue size exceeds Slowlog-max-len, and the latest log is added to the Slow log, and so on.

The following command allows the slow log to hold up to 1000 logs:

CONFIG SET Slowlog-max-len 1000.

Use the CONFIG get command to query the current values of two options:

Redis> CONFIG Get Slowlog-log-slower-than
1) "Slowlog-log-slower-than"
2) "1000"
Redis> CONFIG Get Slowlog-max-len
1) "Slowlog-max-len"
2) "1000"

View Slow Log

To view the slow log, you can use the Slowlog get or slowlog getting number command, which prints all the slow log, and the maximum length depends on the value of the Slowlog-max-len option, while the Slowlog getting number Only the specified number of logs is printed.

The unique ID of the log is reset only when the Redis server restarts, which avoids duplication of the log (for example, you may want to email you each time a new slow query is found).

View the number of current logs

Use the command Slowlog LEN to view the number of current logs.

Notice the difference between this value and the Slower-max-len, which is the number of current logs and the maximum number of logs allowed to be logged.

Empty Log

Use the command Slowlog RESET to empty slow log.

 

INFO

Returns various information and statistics about the Redis server.  

CONFIG Get parameter

The config get command is used to obtain the configuration parameters (configuration parameters) of a running Redis server, although not all configuration parameters are supported by the CONFIG get command.

CONFIG get accepts a single parameter parameter as the search keyword, looking for all matching configuration parameters, where the parameters and values are arranged in "key-value pairs" (Key-value pairs).

For example, if you execute the CONFIG get s* command, the server returns the values of all configuration parameters and parameters that begin with S:

 

CONFIG SET parameter value

The config set command can dynamically adjust the configuration of the Redis server (configuration) without rebooting.

You can use it to modify configuration parameters, or to change the Redis (persistence) method.

Config set can be modified by using the command CONFIG get * To list all configuration parameters modified by config set to take effect immediately.  

CONFIG Resetstat

Reset some statistics in the INFO command, including: Keyspace hits (number of key space hits) Keyspace misses (key space misses) number of commands processed (number of executions) Connections received (number of connections to server) number of expired keys (quantity of Expired key )

DEBUG OBJECT Key

Returns the debug information for the given key.  

DEBUG Segfault

Cause the Redis server to crash, adjust the trial.  

MONITOR

Real-time print out the Redis server received the command, adjust the trial.  

SYNC

Internal commands for the replication feature (replication).

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.