Redis__windowsserver Master-Slave service deployment and invocation instances

Source: Internet
Author: User
Tags install redis

First, talk about the installation of a single Redis service

        use of Redis is 2.8.17 version, downloaded from the official website extract the contents of:               &NBSP ;     Installing and starting a Redis service is simple, as follows:            1, configuring the log file directory: Use only the Modify logfile to navigate to the log folder   & nbsp                          2, command line locator to the directory to extract files     &NB Sp             cd/d D:\MasterRedis-2.8.17     (Windows 7)     &NB Sp             cd/d D:\SlaveRedis-2.8.17        ( Windows Server)             3, installing Redis:redis-server--service-install redis.windows.conf-- LogLevel verbose            4, start Redis:redis-server--service-start             5, stop Redis:redis-server--service-stop            6, Uninstalling Redis:redis-server--service-uninstall    Second, we turn to the conclusionAfter a half-day toss, the conclusion is: success! The process I'll talk about next, the conclusion is to deploy the master-slave service on a single Windows servers machine, the second Redis example will never start (solved when writing this article), can be successfully deployed on two different servers
Iii. Talk about the process1, would like to install the deployment of a single redis continuous operation two times, only to find that the first operation has started a service called Redis, the second operation when the service is not installed at all, the solution is to give the Redis service named, the command is as follows: Redis-server-- Service-install redis6379.windows.conf--loglevel verbose--service-name Redis6379--service-name is the service name, the pit daddy is I copy the life on the net So there is only one bar (-), half a day do not get the desired results (a hillock will also create a service named Redis) 2, the installation of the service when added servicename, in the service start, stop, uninstall also need to add servicename parameter 1, service Start: Redis-server--service-start--service-name Redis6379 redis6379.windows.conf          2, Service stop: Redis-server--service-stop--service-name Redis6379 redis6379.windows.conf 3, service uninstall: Redis-server--servi Ce-uninstall--service-name Redis6379 redis6379.windows.conf 3, finally talk about why the master-slave service can be installed successfully, but the second service will never start after starting a service Pits    The message for the Event Viewer is as follows: (unintelligible!) )          Pit just in the command to install the service: Redis-server--service-install--service-name Redis6379 redis6379.windows.conf--loglevel verbose (not OK) Redis-server--service-install redis6379.windows.conf--loglevel verbose--service-name Redis6379 (OK) See clearly, it is the location of the Service-name parameter, not before the configuration file, must be placed in the last v. Talk about changes to the configuration file (redis.windows.conf)1, the Master Redis service configuration file does not have to make the modification possibly this place needs to modify, I did not do the test 2, changes from the Redis service configuration file are as follows: 1, Port modification 2, currently see here not Make changes, comment 3, log file 4, specify the IP and port of the primary Redis service v. Cut a diagram to illustrate the conclusion (the tool used is Redisdesktopmanager)1. Redisremotemaster is the master Redis for remote host
2, Redisremoteslaver for remote host from Redis (can see start master Redis not set ABC, return is NULL, set, return new value) 3, redislocal as host from Redis (same as 2) v. Calling the Redis code 1, configure the master-slave server
<appSettings>    <!--redis Write server address, you can add multiple servers through,    <add key="readwritehosts  " value="192.168.1.100:6379" />    <!--redis Read server address, you can add multiple servers through, Split--    <add key="readonlyhosts" value= " 192.168.1.100:6380,127.0.0.1:6379" />  </appSettings>

2. Redis Initialization (RedisConfig.cs )

classRedisconfig { Public Staticredisclient Redis {Get            {                return(redisclient) reidspools.getclient (); }        }        Private Static string[] hosts; Private StaticPooledredisclientmanager Reidspools; StaticRedisconfig () {varReadwritehosts = configurationmanager.appsettings["readwritehosts"]. Split (','); varReadonlyhosts = configurationmanager.appsettings["readonlyhosts"]. Split (','); Reidspools=NewPooledredisclientmanager (readwritehosts, Readonlyhosts,NewRedisclientmanagerconfig {maxwritepoolsize= -,//number of "write" link pool linksMaxreadpoolsize = $,//"read" link pool link numberAutoStart =true, Defaultdb=0            }); }    }

3. Redis Operation Tool Class (RedisHelper.cs)

 Public classRedishelper {/// <summary>        ///Get Value/// </summary>        /// <typeparam name= "T" ></typeparam>        /// <param name= "key" ></param>        /// <returns></returns>         PublicT get<t> (stringkey) {            using(varRedis =Redisconfig.redis) {returnRedis. Get<t>(key); }        }        /// <summary>        ///Setting the value/// </summary>        /// <typeparam name= "T" ></typeparam>        /// <param name= "key" ></param>        /// <param name= "value" ></param>        /// <returns></returns>         Public BOOLSet<t> (stringkey, T value) {            using(varRedis =Redisconfig.redis) {returnRedis. Set<t>(key, value); }        }        /// <summary>        ///Setting the value/// </summary>        /// <typeparam name= "T" ></typeparam>        /// <param name= "key" ></param>        /// <param name= "value" ></param>        /// <returns></returns>         Public BOOLSet<t> (stringkey, T value, DateTime DT) {            using(varRedis =Redisconfig.redis) {returnRedis. Set<t>(key, value, DT); }        }    }

4. Calling code

 class   program { static  void  Main (string  [] (args) { var  Redis = new Redishelper (); Redis. Set  <string  > ( " AA   , DateTime.Now.ToString ());  var  d = redis. Get<string  > ( " AA   ); }    }

Redis__windowsserver Master-Slave service deployment and invocation instances

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.