Redis is a distributed cache service. Caching is also an indispensable means for large-scale system development and performance optimization. At this time, Redis was born. Since Redis caches data in the memory stick, its reading and writing speeds are very fast. Traditional relational databases are all on disk, so if you are filtering and querying a particularly large amount of data, it will be very slow, which will undoubtedly affect the users of our system. The installation of redis is also very simple. We still use docker to install redis 1. Download redis from the docker repository #Search for redis in the docker repository docker search redis #Download redis to the local warehouse without adding version number. The default is the latest version. docker pull redis #View the downloaded container docker images 2. Use Docker to create and run the redis image and set the redis password #Use docker run to create and start the container#--requirepass Set the password for connecting to redis docker run -p 6379:6379 --name redis -d redis:latest --requirepass "123456" #Check if the container has been started docker ps 3. Connect to redis locally #Local connection directly uses bash command to set the password and access with -a plus password [root@apg-server ~]# docker exec -it redis redis-cli -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. #set a key test 127.0.0.1:6379> set name xiaomianyang OK #Query the key 127.0.0.1:6379> get name "xiaomianyang" 4. Check the redis container IP address [root@apg-server ~]# docker inspect redis | grep IPAddress "SecondaryIPAddresses": null, "IPAddress": "172.17.0.4", "IPAddress": "172.17.0.4", 5. Connect to redis remotely #If it is on the local machine, use localhost, if it is somewhere else, use the host machine ip [root@apg-server ~]# docker exec -it redis redis-cli -h localhost -p 6379 -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. localhost:6379> get name "xiaomianyang" At this point, redis has been successfully installed in docker. Later, when we use springBoot development, we can take advantage of the cache to improve the processing power of the system. Supplementary knowledge: The complete process of installing Redis in Docker and configuring remote connection & precautions for pitfalls 1. Install Redis Download the redis image through docker search redis and docker pull redis 2. Create a new mount configuration folder Because of the default configuration of redis, you will find that you can only connect locally and cannot access remotely. Using Redis Desktop Manager to connect will result in an error, so you need to manually mount the redis configuration file Create two new folders, data and conf, in any location. eg:
3. Add the configuration file redis.conf Create a new file redis.conf in the newly created redis/conf with the following content: #bind 127.0.0.1 //Allow remote connection protected-mode no appendonly yes //persistence requirepass 123456 //password 4. Create and start the redis container The execution command is as follows:
The interpretation is as follows: –name: Give the container a name -p: port mapping host: container -v: Mount custom configuration custom configuration: container internal configuration -d: Run in the background redis-server --appendonly yes: Execute the redis-server startup command in the container and turn on the redis persistence configuration 5. Startup successful, check the status Check the startup status through docker ps to see if it is successful 6. Test the connection inside the container Execute the docker exec -it my_redis redis-cli command to enter the terminal. Log in using auth password. The completed command is as follows: [root@*** conf]# docker exec -it my_redis redis-cli 127.0.0.1:6379> set name wangcai (error) NOAUTH Authentication required. 127.0.0.1:6379> auth 123456 OK 127.0.0.1:6379> set name wangcai OK 127.0.0.1:6379> get name "wangcai" Note: If this error occurs:
Explanation: No password was entered for verification. Please enter: auth your password 7. Connect using the Redis Desktop Manager client The interface is simple and easy to understand at a glance. Here are the pictures. 8. Summary When an error occurs when starting the container port, you can use netstat -lntp | grep 6379 to check which program is occupying the port. You can kill the program occupying the port through sudo kill 6379 If you use Alibaba Cloud, please be sure to open the corresponding port The above operation of installing redis in docker, setting password and connecting is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: js to create a carousel effect
>>: Sqoop export map100% reduce0% stuck in various reasons and solutions
<br />The author used to be a novice in web ...
In order to avoid repeatedly entering the Docker ...
as follows: docker run -d -p 5000:23 -p 5001:22 -...
1. Business scenario introduction Suppose there i...
The order in which the browser loads and renders H...
Anyone who has used Windows Remote Desktop to con...
This article shows you how to use CSS to create a...
I believe that everyone needs to reinstall MySQL ...
Get daily statistics When doing a project, you ne...
1. Install Python 3 1. Install dependency package...
Preface When using RabbitMQ, if there is no traff...
Since we are going to upload pictures, the first ...
There are always some problems when configuring n...
Table of contents Data Brokers and Events Review ...
This article uses examples to describe MySQL tran...