当前位置:网站首页>Knowledge supplement: basic usage of redis based on docker
Knowledge supplement: basic usage of redis based on docker
2022-07-01 04:06:00 【MagicKong21】
Redis brief introduction
Redis(Remote Dictionary Server) By Salvatore Sanfilippo Developed key-value( Key value pair ) The storage system .
Traditional database ( Relational database ) | NoSQL | |
|---|---|---|
| representative | MySQL、Oracle、SQL Server | Redis、MongoDB |
| data structure | With “ surface ” In the form of ( The table structure has strict data schema constraints ) | Use a relatively simple data structure ( such as Redis Key value pairs are used ) |
| physical position | Stored on a hard disk ( Routine situation ) | Stored in memory ( Supports persistence to disk ) |
| Applicable scenario | Store large-scale data | Small amount of data but certain performance requirements |
According to the project practice experience in the industry ,Redis The main advantages are as follows :
- Because the data is stored in memory , Therefore, the speed of searching data is faster .
- More data types are supported , For example, support string 、 Lists and hash tables .
- Can support transactions , At the same time, it supports data persistence , That is, the data in the memory can be stored in the hard disk .
however ,Redis There are also some disadvantages :
- Redis It is difficult to support online capacity expansion , Especially in the cluster scenario , When the storage capacity reaches the upper limit , Online capacity expansion will be very difficult .
- Redis It's memory based , If a large amount of data is stored in a short time , May cause memory problems , For example, there will be OOM( out of memory ) abnormal .
- Redis The working time is based on single thread , So we can't make full use of the CPU.
In the project , be based on Redis Advantages and disadvantages , It is usually used for caching 、 seckill 、 Counters, leaderboards and other scenarios closely related to performance ( And it is more suitable to provide services in the form of distributed clusters ).
Docker brief introduction
Docker Three concepts of : Warehouse 、 Mirror image 、 Containers
- Warehouse : Code Center , Can be locally , It can also be remotely , The ability to store images .
- Mirror image : Static .
- Containers : Mirror runtime entities ( Objects instantiated by classes ).

In the sense of development Docker contain Docker Software and Docker command .
Docker Official website :https://www.docker.com/
Check the installed version ( Command line ):docker version
View local image :docker images
Download mirroring :docker pull Mirror name : label ( If you don't specify a label , The default is latest, The latest version )

delete mirror :docker rmi Mirror name : label or docker rmi Mirror image ID
Running the mirror :docker run -it Mirror name : label /bin/bash
(-it Means interactive operation at the terminal ,/bin/bash Indicates the command to be executed after the container is started , Here is the start shell)

View all current containers :docker ps -a( By default, only those in Up The container of state , With parameters -a To display all )

Delete container :docker rm Containers ID

function Redis Mirror image :docker run -itd --name myFirstRedis -p 6379:6379 redis:lastest
-it Interactive operation at the terminal
d Means running in the background
--name Specify the name of the container
-p Of the specified container 6379 Port mapping to host ( function Docker Machine ) Of 6379 port ( This allows you to host outside the container ip:6379 The way to access Redis service )

( be known as myFirstRedis The container of is in Up state , And through 6379 The port provides external services )
see Redis Activation effect :docker logs myFirstRedis

adopt docker exec Get into Redis Containers :docker exec -it myFirstRedis /bin/bash
(docker exec Indicates that the command is executed in the run container ,/bin/bash Indicates the specific command to be executed , Here is the opening shell)

( Enter the file named myFirstRedis The container of , The container is based on Linux operating system . Re pass redis-cli Command to create a client —— Connected to the container Redis The server , Subsequently passed set The command creates a value of Hugo Of name Variable , Re pass get Command to get name The value of the variable )

( Pass twice exit go back to Windows Command line . The first time you quit is with redis-cli Entering Redis Run window , The second time you quit is with docker exec Order to enter Linux Containers )
Stop container :docker stop myFirstRedis( Be careful : What stops is the container , instead of Redis service )
Restart container :docker start myFirstRedis or docker restart myFirstRedis
( difference : direct docker restart The file system associated with the container will not be mounted , In other words, the changed configuration item parameters may not be loaded . So it is suggested to docker stop, Again docker start)

see Redis Version of

Open the container , Into the container shell
see Redis Server version :redis-server --version
see Redis Client version :redis-cli --version
The whole process is sorted out :
- install Docker Software
- Enter... On the command line docker pull redis Download the latest Redis Mirror image
- Input docker images To confirm the image
- Input docker run -itd --name myFirstRedis -p 6379:6379 redis:latest, Create and run a container based on the image
- Input docker ps -a Check the corresponding created container
- Input docker stop myFirstRedis Let the container enter Exited state
- Input docker rm myFtrstRedis Delete container ( Before deleting, you must ensure Exited state )
- Input docker start myFirstRedis Start in Exited The container of state
- After the container is created and started , Can pass docker logs myFirstRedis Check the container Redis Start up of the server
- It can also be done through docker exec -it myFirstRedis /bin/bash Enter the container and start shell
- start-up shell And then you can go through redis-cli Create a connection to Redis The client side of the server ( Then, various Redis command , such as exit Exit command )
- If you need to restart the container , First of all docker stop myFirstRedis, Again docker start myFirstRedis To achieve
- Need to stop Redis Server , Through the first redis-cli Command to connect to the server , Input again shutdown To achieve
Inductive graph

< End >
边栏推荐
- “目标检测“+“视觉理解“实现对输入图像的理解
- [today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
- 浏览器顶部loading(来自知乎)
- Network metering - application layer
- 389. find a difference
- In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
- 30. 串联所有单词的子串
- Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
- 盘点华为云GaussDB(for Redis)六大秒级能力
- 不同性能测试工具的并发模式
猜你喜欢

Future of NTF and trends in 2022

Do280 management application deployment --rc

盘点华为云GaussDB(for Redis)六大秒级能力

Grid system in bootstrap

Jenkins automatically cleans up construction history

互联网行业最佳产品开发流程 推荐!

JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction

Volley parsing data shows networking failure

283.移动零

定了!2022京东全球科技探索者大会之京东云峰会7月13日北京见
随机推荐
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
JMeter login failure, extracting login token, and obtaining token problem solving
Volley parsing data shows networking failure
[ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
LeetCode 1380. Lucky number in matrix
Hololens2 development environment building and deploying apps
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
Quickly filter data such as clock in time and date: Excel filter to find whether a certain time point is within a certain time period
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
创新界,聚势行 | 2022人大金仓“百城巡展”火热开启
Unexpected token o in JSON at position 1, JSON parsing problem
跳槽一次涨8k,5年跳了3次...
187. 重复的DNA序列
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
25.K个一组翻转链表
241. Design priorities for operational expressions
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
浏览器顶部loading(来自知乎)
214. 最短回文串
【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹