当前位置:网站首页>Redis learning notes (2) - power node of station B
Redis learning notes (2) - power node of station B
2022-07-25 01:21:00 【KK-Greyson】
List of articles
008- redis The business of
8.1 Introduce

8.2 Common commands
(1)multi

(2)exec

(3)discard

(4)watch

(5)unwatch

8.3 Summary

009- redis Publish and subscribe messages ( understand )





010- redis Master-slave replication of
10.1 Introduce
Main library master Write data Slave Library slave Read the data
After the main database reads the data Copy data to the slave Library
This can improve efficiency
After the host data is updated, according to the configuration and Policy , Automatic synchronization to slave master/slave Mechanism ,Master Write first ,Slave Mainly reading .

10.2 Build one master and two slaves
Just watch the video here




17、redis Master-slave replication of : From less to more 、 Write and read 、 Read / write separation 、 Master write synchronous replication to slave .
Build one master and two slaves redis colony :
1)、 Build three redis service : Use one redis Simulate three redis service
Provide three points redis The configuration file :redis6379.conf、redis6380.conf、redis6381.conf
Modify three configuration files : With redis6379.conf For example
bind 127.0.0.1
port 6379
pidfile /var/run/redis_6379.pid
logfile "6379.log"
dbfilename dump6379.rdb
Use three... Respectively redis The configuration file , Start the three redis service :
redis-server redis6379.conf &
redis-server redis6380.conf &
redis-server redis6381.conf &
2) adopt redis The client is connected to three servers respectively redis service :
redis-cli -h 127.0.0.1 -p 6379
redis-cli -h 127.0.0.1 -p 6380
redis-cli -h 127.0.0.1 -p 6381
3) Check three redis The master-slave role of services in the cluster :
info replication
By default , be-all redis Services are hosts , That is, you can write and read , But they haven't been from the machine yet .
4) First in 6379 Write operation :
set k1 v1
Three stations rdis Services are independent of each other , They don't influence each other .
5) Set up master-slave relationship : Set never set the master
stay 6380 On the implementation :slaveof 127.0.0.1 6379
stay 6381 On the implementation :slaveof 127.0.0.1 6379
6) Copy in full : Once the master-slave relationship is determined , It will automatically copy the existing data on the master database to the slave database .
stay 6380 and 6381 On the implementation :keys *
7) Incremental replication : The data written by the master database will be automatically synchronized to the slave database .
stay 6379 On the implementation :set k2 v2
stay 6380 and 6381 On the implementation :keys *
8) Write and read , Read / write separation :
stay 6380 and 6381 On the implementation :set k3 v3 ===> Report errors
9) Host down 、 The slave stands by :
close 6379 service :redis-cli -h 127.0.0.1 -p 6379 shutdown
see 6380 and 6381 The master-slave role of the service :info replication
10)、 Host recovery 、 Everything is back to normal :
restart 6379 service :redis-server redis6379.conf &
Client connection 6379:redis-cli -h 127.0.0.1 -p 6379
11)、 From the machine down 、 The master is one less slave 、 Other slaves remain unchanged :
close 6380 service : redis-cli -h 127.0.0.1 -p 6380 shutdown
see 6379 The master-slave role of the service :info replication
see 6381 The master-slave role of the service :info replication
12)、 Recover from the machine 、 You need to reset the master-slave relationship :
restart 6380 service :redis-server redis6380.conf &
Client connection 6380:redis-cli -h 127.0.0.1 -p 6380
stay 6380 On the implementation : slaveof 127.0.0.1 6379
13)、 Slave host :
a) Host down 、 The slave stands by :
close 6379 service :redis-cli -h 127.0.0.1 -p 6379 shutdown
see 6380 and 6381 The master-slave role of the service :info replication
b) The slave disconnects the original master-slave relationship :
stay 6380 On the implementation :slaveof no one
see 6380 The master-slave role of the service :info replication
c) Reset the master-slave relationship :
stay 6381 On the implementation :slaveof 127.0.0.1 6380
d) Previous host recovery 、 Become a loner :
restart 6379 service :redis-server redis6379.conf &
Client connection 6379:redis-cli -h 127.0.0.1 -p 6379
e) Heaven becomes hell :
stay 6379 On the implementation :slaveof 127.0.0.1 6381
stay 6381 On the implementation :info replication It is both a master and a slave
Summary : One host is configured with multiple slaves , One slave can be configured with multiple slaves , Thus forming a huge cluster architecture .
Reduce the pressure of a host , But it increases the delay time between services .
10.3 The principle of replication
(1) Copy in full

(2) Incremental replication

10.4 Sentinel mode

18、redis Sentinel mode : Host down 、 The automatic version of the slave computer .
1) Build a one master and two slave cluster architecture :(17 Five steps before the festival )
2) Provide sentry profile :
stay redis Create a configuration file under installation :redis_sentinel.conf
sentinel monitor dc-redis 127.0.0.1 6379 1
3) Start sentinel service :
redis-sentinel redis_sentinel.conf
4) Host down :
close 6379 service :redis-cli -h 127.0.0.1 -p 6379 shutdown
The sentinel program automatically selects the slave computer .
5) Previous host recovery : Automatically subordinate to the new host .
restart 6379 service :redis-server redis6379.conf &
Client connection 6379:redis-cli -h 127.0.0.1 -p 6379
10.5 Summary

011- Jedis operation Redis
19、java operation redis database :
jedis yes redis Officially provided operation redis Data technology .
Put all the redis Instructions are defined as java Method of tool class , Method name and redis The instruction name of is exactly the same ;
Development is accessed through programs redis, Just use the tool class and its methods .

stay java Program access redis:



1) establish maven Version of webapp engineering
2) add to jedis rely on
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.1.0</version>
</dependency>
3) establish Jedis Connect
* close linux The firewall of










012- redis Client connection tool for
It's like mysql equally have access to navicat
redis There are similar navicat The same thing :
But for redis, There is no difference between using and not using the visual interface


边栏推荐
- Human cell prosci 4-1BB ligand recombinant protein scheme
- Unity3d calls between different script functions or parameters
- If in ython__ name__ == ‘__ main__‘: Function and principle of
- 360 interview summary 2013 campus recruitment 2012-4-4
- Document the use of anti shake in packaged components and projects
- Breederdao's first proposal was released: the constitution of the Dao organization
- The current situation of the industry is disappointing. After working, I returned to UC Berkeley to study for a doctoral degree
- record
- Data governance notes
- BisinessCardGen
猜你喜欢

The two supply chain centers of HEMA launched the "background" of innovative research and development of multi format commodities

Introduction to thread pool

Esp32 OLED lvgl displays common Chinese characters

Several schemes of traffic exposure in kubernetes cluster
![[performance optimization] MySQL common slow query analysis tools](/img/97/c7604282544c5fa8cd7e85a6ab9154.png)
[performance optimization] MySQL common slow query analysis tools

Luo min cannot become Dong Yuhui

Summary of MATLAB basic grammar
10 commonly used data visualization tool software

From casting sword to defending sword: the way to build the efficiency platform of didi project

Tiktok iqiyi announced cooperation, long and short video handshake and reconciliation?
随机推荐
第四章 驱动子系统开发
Musk responded whether he would upload his brain to the cloud: already did it!
JS convert pseudo array to array
BisinessCardGen
Human cell prosci 4-1BB ligand recombinant protein scheme
进程的几种状态
Educational codeforces round 89 (rated for Div. 2) ABC problem solution
Shell judges whether the file exists and whether the file size is 0
Kubernetes creates a user with dashboard read-only permission (with exec permission)
Synchronization primitive: lock
About the difference between for... In and for... Of and object. Keys()
Redis 事务学习有感
Top priority of dry goods: common indicators and terms in data analysis!
Interview questions
Several states of the process
The position of the nth occurrence of MySQL in the string
Amd epyc 9654 Genoa CPU cache test exposure L1 bandwidth up to 30tb/s
ES6 modularization
How to implement a state machine?
Worthington cytochrome c digestion study carboxypeptidase B scheme