Redis Study Notes ~ Redis implements multiple slave storage servers for read/write splitting

Source: Internet
Author: User
Tags redis server

Back to directory

Redis, A nosql storage system, is generally deployed in Linux. we can regard it as a data server. When concurrency is high, we will use multiple servers to act as redis servers, at this time, redis is also distributed, and redis and WWW are also distributed. We do not need to intervene in the distribution between redis, it is linked by our redis client. The server to which you are linked is completely controlled by the client.

Next, let's take a look at the related configurations in redisconfig. I have added some instructions.

/// <Summary> /// configuration parameters of redis main information /// </Summary> Public sealed class redisconfiginfo: configurationsection {public static redisconfiginfo getconfig () {redisconfiginfo section = (redisconfiginfo) configurationmanager. getsection ("redisconfig"); Return section;} public static redisconfiginfo getconfig (string sectionname) {redisconfiginfo section = (redisconfiginfo) configurationmanager. getsection ("R Edisconfig "); If (Section = NULL) throw new configurationerrorsexception (" section "+ sectionname +" is not found. "); Return section ;}/// <summary> /// writable redis link address, separate multiple hosts with commas // </Summary> [configurationproperty ("writeserverlist", isrequired = false)] Public String writeserverlist {get {return (string) base ["writeserverlist"];} set {base ["writeserverlist"] = value ;}/// <summary> // readable The redis link address. Multiple hosts are separated by commas. // </Summary> [configurationproperty ("readserverlist", isrequired = false)] Public String readserverlist {get {return (string) base ["readserverlist"];} set {base ["readserverlist"] = value ;}} /// <summary> /// maximum number of write links /// </Summary> [configurationproperty ("maxwritepoolsize", isrequired = false, defaultvalue = 5)] public int maxwritepoolsize {get {int _ maxwritepoolsize = (INT) base ["maxwritepoolsize"]; return _ maxwritepoolsize> 0? _ Maxwritepoolsize: 5 ;}set {base ["maxwritepoolsize"] = value ;}} /// <summary> /// maximum number of read links /// </Summary> [configurationproperty ("maxreadpoolsize", isrequired = false, defaultvalue = 5)] public int maxreadpoolsize {get {int _ maxreadpoolsize = (INT) base ["maxreadpoolsize"]; return _ maxreadpoolsize> 0? _ Maxreadpoolsize: 5 ;}set {base ["maxreadpoolsize"] = value ;}} /// <summary> /// Automatic Restart /// </Summary> [configurationproperty ("autostart", isrequired = false, defaultvalue = true)] public bool autostart {get {return (bool) base ["autostart"] ;}set {base ["autostart"] = value ;}} /// <summary> /// expiration time of the local cache (timeout), in the unit of seconds /// </Summary> [configurationproperty ("localcachetime", isrequired = false, defaultvalue = 36000)] public int localcachetime {get {return (INT) base ["localcachetime"];} set {base ["localcachetime"] = value ;}} /// <summary> /// whether to record logs. This setting is only used to troubleshoot redis running problems, such as redis working properly, disable this item // </Summary> [configurationproperty ("recordelog", isrequired = false, defaultvalue = false)] public bool recordelog {get {return (bool) base ["recordelog"];} set {base ["recordelog"] = value ;}}}

In the configuration file, we can configure the redis read server and write server. multiple servers are separated by commas (,) (redis itself supports read/write splitting)

  <RedisConfig WriteServerList="192.168.2.71:6379,192.168.2.72:6379" ReadServerList="192.168.2.71:6379,192.168.2.72:6379" MaxWritePoolSize="60" MaxReadPoolSize="60" AutoStart="true" LocalCacheTime="180" RecordeLog="false">  </RedisConfig>

We can use multiple threads to test the function.

// Testing redis 100 threads for (INT I = 0; I <100; I ++) {task. run () => {using (VAR redisclient = redismanager. getclient () {using (VAR test = redisclient. gettypedclient <string> () {test. lists ["print"]. enqueue ("information added"); var S = test. lists ["print"]. dequeue (); response. write (s); response. write (redisclient. host); response. write ("<br> ");}}});}

The test result is that a redis server is randomly allocated for each client request. Let's take a look.

The figure above shows that our information is written to two redis servers, and the problem arises again. When the client retrieves data, you may retrieve the data in redisserver1, it is also possible to take the data in redisserver2, and the real complete data is the union of the two servers. How to merge the data of multiple servers is a problem we need to solve, if this problem cannot be solved, it will be meaningless for multiple servers. In the next section, we will mainly discuss the data synchronization problem of multiple redisservers.

Back to directory

Redis Study Notes ~ Redis implements multiple slave storage servers for read/write splitting

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.