Redis Database Master Copy configuration detailed

Source: Internet
Author: User
Tags redis port number

First, copy basic configuration and demo

In order to avoid a single point of failure, Redis provides a copy function that enables the process of automatic synchronization.

1, configuration

The data after synchronization is divided into two categories: one is the primary database (master) and the other is from the database (slave). The primary database can read and write, and automatically synchronizes the data to the database when a write operation occurs. The data is generally read-only and accepts data synchronized by the primary database.

In Redis, the primary database does not need to be configured by adding the "Salveof Primary database Port" to the configuration file of the database, using the replication feature.

2, Redis replication demo

Below we start two Redis instances on the same server, listening on different ports, one as the primary database and the other as from the database.

First, we want to replicate a Redis service configuration file and name it redis6380.conf.

  

We modify the port number in the redis6380.conf configuration file to 6380 and configure the Redis instance as the primary database from the database.

  

Configuration from the database

  

I then made two bat batch files that started Redis to start two Redis databases:

  

The content is:

Redis-server  redis.windows.conf    //Start primary database

Redis-server  redis6380.conf       //boot from database

Now we start the client of the master-slave database:

The client of the primary database is under the Redis installation directory, double-click Redis-cli.exe.

  

From the start of the database, we opened CMD, entered the Redis directory, entered

  

In this way, we have two Redis database server and client, the following is to demonstrate the functionality of replication:

First, enter in the primary database

  

Then, at the client from the database, we do the query operation

  

You can see the value of the Name property that was fetched from the database.

Note: In addition to setting the Slaveof parameter through a configuration file or command line, you can modify it at run time using the slaveof command:

  

If the database is already from a database of other primary databases, the slaveof command stops synchronizing with the original database and synchronizes with the new database.

second, the principle of reproduction

When a database is started, the Sync command is sent to the primary database, the primary database starts saving the snapshot in the background after receiving the Sync command, and caches the commands received during the save. When the snapshot is complete, Redis sends the snapshot files and all cached commands to the database, which are received from the database, and the snapshot files are loaded and the cached commands are executed. This is done again after the master-slave database is disconnected from the reconnect.

Iii. persisting from the database

To improve performance, you can use a copy of a feature resume several from the database and enable persistence from the database while disabling persistence in the main data. Restarting the data when you crash from the database automatically synchronizes the data, so you don't have to worry about data loss. When the primary database crashes, the new data can be synchronized by using the slaveof no one command from the database to promote the primary data from the database and then using the slaveof command to set the original primary database to the new primary database from the database.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.