Redis's Replication (copy)

Source: Internet
Author: User

Http://www.cnblogs.com/stephen-liu74/archive/2012/02/23/2364717.html

Read/write separation

Configuration file is redis.conf file

How to configure replication:


See the following steps:
1). Start two Redis servers at the same time, consider starting two Redis servers on the same machine, listening to different ports, such as 6379 and 6380, respectively.
2). Execute the command on the slave server:
/> Redis-cli-p 6380 #这里我们假设Slave的端口号是6380
Redis 127.0.0.1:6380> slaveof 127.0.0.1 6379 #我们假设Master和Slave在同一台主机, Master has a port of 6379
Ok
The above method only guarantees that after executing the slaveof command, redis_6380 becomes the slave of redis_6379, and once the service (redis_6380) restarts, the replication relationship between them terminates.
If you want to guarantee the replication relationship between the two servers over the long term, you can make the following changes in the redis_6380 configuration file:
/> Cd/etc/redis #切换Redis服务器配置文件所在的目录.
/> ls
6379.conf 6380.conf
/> VI 6380.conf
Will
   # slaveof <masterip> <masterport>
Switch
slaveof 127.0.0.1 6379
Save exit.
This ensures that the REDIS_6380 Service program will actively establish a replication connection to the redis_6379 after each boot.

After configuration, you can write read operation.

Public ActionResult Testwrite ()//Master Service

{

var client = new Redisclient ("127.0.01", "6379");

Client. Set<int> ("pwd8800", 1111);

Return content ("OK");

}

Public ActionResult Testread ()//Sub-service

{

var client = new Redisclient ("127.0.01", "6379");

int pwd = client. Get<int> ("pwd8800");

return content (pwd. ToString ());

}

Save 900 1 means that after 900 seconds a key has changed to perform a saving

Modify the AppendOnly configuration to start the AOF mode, change to Yes and start aof mode, save data in real time, but affect performance

Appendfsync No/always/everysec always indicates that each command is written once, the performance is the worst; no OS is synchronized to disk, persistence is not guaranteed, performance is best, everysec is synchronized once per second, performance tradeoff. First, you want to enable AOF mode.

AOF files are growing faster, so

Added bgrewriteaof functionality since 2.4, overwriting aof files in the event of a low load

Improving performance can:

The main service shuts down the Save function;

Open the AOF function from the server, and turn on the BGREWRITEAOF function, do not provide service

If an RDB (snapshot), AOF is configured at the same time, only the AOF is loaded when recovering data

If only an RDB snapshot is configured, the dump file recovery will be loaded upon recovery

Redis's Replication (copy)

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.