Redis command-line tool can be used so you know it?

Every day we are using Redis built-in command line tool redis-cli, over time that it is a simple interactive Redis data structures manual procedures, but behind it is a powerful majority of students may unheard of. In this section we dig up a little-known interesting use of these.

To execute a single command

Usually in accessing Redis server, usually using redis-cli enter interactive mode, and then a question and answer to read and write server, in this case we use its "interactive mode." There is another kind of "direct mode", the instruction is executed by the command parameter passed directly to redis-cli and get the output.


If the output is large, you can redirect the output to an external file


The above command server is pointing to the default server address, if you want to point to a specific server can do

Batch Run

In the development process in the usual line, sometimes we will inevitably have to manually create the data, and then import Redis. We usually write scripts to do it. But there is another more convenient way, and that is directly redis-cli to execute batch series of instructions.


The above instruction uses the Unix pipes connected to the redis-cli cat standard input standard output instruction. In fact, you can also directly use the input redirection command batch execution.


set multi-line strings

If a string of more than one line, you want it to incoming set of instructions, how redis-cli to do? You can use the -x option, which will use the contents of standard input as the last parameter.


Repeat instructions

redis-cli further supports execution of instructions is repeated a plurality of times, each instruction is provided a time interval between the execution, so they can observe the content of an instruction output changes with time.


If the number is set to -1 that is repeated countless times never implemented. If no -i parameter, then there is no interval, continuously repeated. In interactive mode instructions may be repeatedly performed, rather strange form, increasing the number of instructions at the front


Export csv

redis-cli can not export the contents of an entire library once as csv, but can export single instruction output csv format.


Of course, this export function is relatively weak, the string is just a collection separated by a comma. But you can combine batch execution command to look at the effect of export multiple instructions.

See here the reader should understand the effect on the output --csv parameter is to do a conversion, separated by commas, that's it.

Lua script execution

In lua script section, we use eval command string to execute the script, the script every time the content is compressed into a single line string and then calling eval command, which is very cumbersome and poor readability. redis-cli take into account this point, it can execute the script file directly.


Here we have the form of a script to execute the above command, in the form of different parameters, it is necessary to use a comma separated between KEY and ARGV, and the number of parameters need to provide KEY


If your lua script is too long, - eval will be of great use.

Monitoring Server Status

We can use --stat parameters to real-time monitoring server status, real-time output time interval of 1s.


If you feel that a pause is too long or too short, you can use the -i parameter to adjust the output gap.

KEY scan large

This feature is too practical, I've tried countless times online. Redis Caton each encounter occasional problems, the first thought is whether there is a large KEY instance, large KEY memory expansion and will lead to the release of the main thread Caton. If you know there are no major KEY, you can write your own program to scan, but it is too cumbersome. Providing --bigkeys redis-cli parameters can quickly scan a large memory KEY, -i parameter control using scanning interval, avoid scanning instructions cause the server ops steep alarm.


redis-cli for each type of object maximum length KEY are recorded for each object type, a refresh time record is output immediately. It can ensure that the output length of Top1 KEY, but Top2, Top3 etc. KEY is not guaranteed to scan out. The general approach is to scan more than a few times, or re-scan confirmed that there is no KEY second largest after the elimination of Top1 KEY.

Sampling server command

Now there is OPS line a Redis server is too high, there are a lot of businesses are using this module Redis, how can we judge them which led to unusually high traffic OPS. In this case instructions may be sampled online server, instructions samples can be analyzed generally observed a high proportion of OPS service points. Then you should use the monitor instructions, instruction it will execute the server instantly displayed all. But use the time to pay attention to even use ctrl + c interrupt, or your display will instantly make crackling too much instruction you dazzled.


Diagnostic server latency

Usually we delay diagnosis of both machines generally use the Unix ping command. Redis also provides a diagnostic delay instruction, but it's not the same principle, it is a diagnosis instruction (PING command) between the machine and the current delay Redis server, it is not just the physical network delay, and also the current Redis about whether the main thread busy. If you find a Unix command ping latency is very small, but significant delay Redis, that there is a weak explanation Redis server Caton during instruction execution.


Delay unit is ms. redis-cli also shows the distribution of delay, and a graphical output.

$ redis-cli --latency-dist

image

The authors do not describe the meaning of the graphics, readers can try to crack it.

Remote Backup rdb

Execute the following command on the remote Redis instance backup to the local machine, the remote server will perform a bgsave operation, then transfer rdb files to the client. Remote backup rdb let us have a "without leaving the whole world to know what" feeling.


Simulation from the library

If you want to observe the master and slave servers are synchronized between those data, you can use redis-cli simulation from the library.


The first thing connected to the main library from the library are full amount of sync, so after seeing the above instructions Caton This is normal, to be the first time the full amount of synchronization is complete, it will output increment aof log.


Ali architect succinctly get information succinctly and video, Dubbo, Redis, design patterns, Netty, zookeeper, Spring cloud, distributed, highly concurrent architectures and other technology, can be added to Advanced Java Road: 878 249 276.


Original Address: https://blog.csdn.net/weixin_33809981/article/details/87999782

Guess you like

Origin www.cnblogs.com/jpfss/p/11014978.html