A small note of commonly used advanced functions such as redis pipelines, transactions, publish and subscribe, expiration, and filters (part 1)

Redis has five data types. Different types of data have different characteristics. Proper use can achieve many special functions. In addition, redis itself also encapsulates or supports some special operations, which can be called advanced functions of redis. .
For the introduction of the basic data structure and application scenarios of
redis, please refer to the previous blog redis data type essential knowledge and application scenarios
. There are many advanced functions of redis. Here are only the following:

Pipeline
Transaction
Publish/Subscribe
Expiration
Bloom filter

pipeline

Personal understanding, pipeline operation should not be considered a unique feature of redis, but it also supports it.
Redis is based on a client-server TCP service. Usually a client initiates a request to the server and listens to the socket return. This process is in blocking mode and waits for the server to respond before proceeding to the next operation.
In this mode, when the same client operates multiple times, the number of interactions is very large. The redis pipeline actually sends multiple client operation requests to the server at once, and then the server returns again, a bit like a packaged delivery process.
In a sense, less interaction times can improve performance.
The basic commands for redis pipeline operations are as follows, using linux echo and nc commands:

echo -e "set k1 123456\nget k1" | nc loalhost 6379

In the above example, set the value of k1 of redis to 123456, and then get the value of k1. The two operations send each server at a time, and use nc to establish a tcp connection interaction.
The operation itself is relatively simple, but I need to know some usages of echo and nc, and I just take this opportunity to learn more.
At the beginning, my understanding of echo was actually writing files, because I didn’t use much, but after a closer look, I found that echo can actually do quite a lot.

echo output to the command line

echo "test"
echo test

The actual effect of the above two commands is the same. Both will output the string content behind echo on the command line interface. This should be the simplest use of echo.

echo write to file

echo test> test.txt

echo append to file

echo test>> test.txt

echo escape

echo -e "set k1 2\nget k1"

Here the -e parameter is used to handle escaping. The above example is actually the content of the redis pipeline operation example at the beginning. The middle of the quotation marks \nmeans a newline character. Adding the -e parameter will parse it into a newline.

Echo uses variable output

This place actually needs to write a linux script. The following is an example of a simple shell script. For example, there is a file called test.sh with the following content:

#!/bin/sh
read name
echo "$name is me"

Executing the above shell script will first input a content, assign it to the variable name, and then output it on the next line.

chmod file permissions

In the above example, to simulate echo using variables and output, a simple shell script is used. When the script file is initially created, it has only read and write permissions and cannot be executed. Therefore, the chmod command is required to modify the permissions of the file, which happens to be Also add some knowledge related to this command.
File permissions are generally represented by octal numbers or English characters:

4 stands for readable, the character r;
2 stands for writable, the character w;
1 stands for executable, the character x;
0 stands for no permission, the character -;
for example, to give all users readable, writable and executable permission to the file test.sh , The following three commands can be used, the effect is the same, but it seems that the digital method is the most convenient:

chmod 777 test.sh;
chmod u=rwx,g=rwx,o=rwx test.sh
chmod ugo=rwx test.sh

u represents the user the file belongs to
g represents the user group the file belongs to
o represents other users

nc

The above pipeline operation also uses the nc command. nc is a netcat command. There are many parameters and usages like echo. A TCP connection is established by default without parameters, for example:

nc 127.0.0.1 6379

The above operations will connect to the local redis service in tcp mode, and then we can perform the same operations as redis-cli after entering the redis client.
In addition to establishing a normal connection, nc has a very convenient function to transfer files. One party establishes a tcp connection to receive, and one party establishes a tcp connection to transmit. The receiver uses the -l parameter to monitor. Examples are as follows:

nc -l 9999 > t.txt

An example of server sending is as follows:

nc localhost 999 <a.txt

There are many nc parameters, and there may not be too many non-professional operation and maintenance. If you want to know more in detail, please refer to the following link for more nc parameters and usage content:
https://www.cnblogs.com /guge-94/p/10719016.html

related articles

Caching and redis related basic knowledge
Linux redis installation and software installation related Linux knowledge points
redis data type key knowledge and application scenarios
redis pipeline, transaction, publish and subscribe, expiration, filter and other common advanced functions (part 1)
redis pipeline, A small note of commonly used advanced functions such as transactions, publish and subscribe, expiration, filters, etc. (Part 2)
Springboot integration and use of redis common functions

Guess you like

Origin blog.csdn.net/tuzongxun/article/details/107646610