当前位置:网站首页>Redis03 - network configuration and heartbeat mechanism of redis
Redis03 - network configuration and heartbeat mechanism of redis
2022-07-04 21:36:00 【Half old 518】
front said
Author's brief introduction : Half old 518, Long distance runner , Determined to persist in writing 10 Blog of the year , Focus on java Back end
Column Introduction : thorough 、 comprehensive 、 Introduction of the system redis knowledge
The article brief introduction : Introduce Redis Network configuration and heartbeat mechanism
Redis Network configuration and heartbeat mechanism
Redis Under the installation root directory of redis.conf The configuration file ,Redis This configuration file will be loaded at startup , Work according to the configuration at run time . Sometimes we take out this document , Store in a separate location , When starting, you must specify which configuration file to use , This document will take effect .Redis The network related configuration of is as follows .
bind: binding IP Address , Other machines can use this IP visit Redis, The default binding 127.0.0.1, That is, any host ip Address , In order to facilitate safety control , We generally recommend changing it to fixed IP Address .port: To configure Redis Ports occupied , The default is 6379.tcp-keepalive:TCP Connect the survival strategy , Can pass tcp-keepalive Configuration item to set , The unit is in seconds , If set to 60 second , be server End meeting every 60 Second to connect idle clients once ACK request , To check if the client has hung up , For unresponsive clients, the connection is closed . If set to 0, No life preservation test will be carried out .
Demo Next , Execute the following command , Modify the bound ip Address .
/opt/redis-5.0.2$ sudo vim redis.conf

start-up redis The server .
redis-server redis.conf &
At this time, if there is no ip Executing client startup cannot start
redis-cli
An error is as follows .
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
here ctrl Add C Back to the command line interface , Appoint ip And port startup .
[email protected]:/opt/redis-5.0.2$ redis-cli -h 192.168.199.213 -p 6379
192.168.199.213:6379>
If you need to close redis The server also needs to specify ip And port number , Because the closing operation is essentially a request sent by the client to the server .
redis-cli -h 192.168.199.213 -p 6379 shutdown
If you execute the above command, the following error message appears .
This is because of your redis-server Is it through root User initiated , and shutdown The operation needs to save the data , You need write permission to the file ( Local users may not ). At this point, we first shut down the server brutally redis-server
$ ps -ef|grep redis
wangzhou 7155 6648 0 16:39 pts/0 00:00:04 redis-server 192.168.199.213:6379
wangzhou 7877 6648 0 17:15 pts/0 00:00:00 grep --color=auto redis
$ kill -9 7155
Bring it with you when you restart the service sudo
sudo redis-server redis.conf &
Connect the client later , You can use the client to shut down the server normally .
TIPS:
Using the server is recommended in root Start or use under the usersudoCommand
Now please think about a question , The number of clients that the server can keep connected is limited , If the client does not actively disconnect after connecting , Is the connection always maintained ? Won't this waste our resources ? therefore ,redis The developers of provide a mechanism to deal with this situation . The server will send requests to the client regularly , If the client is still actually using the server , It will return " Activate " The state of . Parameters in the above configuration tcp-keepalive It is used to set the time interval for the server to send requests .
In development , We generally recommend setting this time to 60s, Specifically, adjust according to the performance of the server .
边栏推荐
- Procurement in software development
- Routing configuration and connectivity test of Huawei simulator ENSP
- Use of redis publish subscription
- 解读创客教育中的各类智能化组织发展
- 解析互联网时代的创客教育技术
- y56.第三章 Kubernetes从入门到精通 -- 业务镜像版本升级及回滚(二九)
- Go语言循环语句(第10课中3)
- Jerry's ad series MIDI function description [chapter]
- Can be displayed in CAD but not displayed in print
- Jerry's ad series MIDI function description [chapter]
猜你喜欢
随机推荐
[weekly translation go] how to code in go series articles are online!!
[wechat applet] collaborative work and release
shp数据制作3DTiles白膜
Huawei simulator ENSP common commands
Stealing others' vulnerability reports and selling them into sidelines, and the vulnerability reward platform gives rise to "insiders"
股票开户佣金最低多少,炒股开户佣金最低网上开户安全吗
【LeetCode】17、电话号码的字母组合
解析互联网时代的创客教育技术
华为ensp模拟器 三层交换机
华为模拟器ensp的路由配置以及连通测试
flink1.13 sql基础语法(一)DDL、DML
华为ensp模拟器 实现多个路由器的设备可以相互访问
【公开课预告】:视频质量评价基础与实践
A quick start to fastdfs takes you three minutes to upload and download files to the ECS
redis事务
2021 CCPC 哈尔滨 B. Magical Subsequence(思维题)
Learning breakout 3 - about energy
MP3是如何诞生的?
【C語言】符號的深度理解
搭建一个仪式感点满的网站,并内网穿透发布到公网 1/2









