Windows版Redis主从配置

一、下载

从github上下载Redis的zip包,地址:https://github.com/MicrosoftArchive/redis/releases

Redis本身不支持windows,这是另外一个团队维护的。

二、安装

1.解压两份,6379是主,6380是从

2.打开6380的redis.windows.conf配置文件

修改端口:

配置主服务器:

3.打开命令窗口,定位到刚才解压的文件夹(两份都安装)

安装服务:
redis-server --service-install redis.windows.conf --service-name Redis6379
卸载服务:
redis-server --service-uninstall redis.windows.conf --service-name Redis6379

安装完了就会在服务中出现如下图,启动它们:

三、测试

 1 using ServiceStack.Redis;
 2 using System;
 3 
 4 namespace ConsoleApplication3
 5 {
 6     public static class CommonRedis
 7     {
 8         public static string RedisPath { get; set; }
 9 
10         public static T Get<T>(string key)
11         {
12             RedisClient client = new RedisClient(RedisPath);
13             T value = client.Get<T>(key);
14             client.Save();
15             client.Dispose();
16             return value;
17         }
18 
19         public static void Set<T>(string key, T value)
20         {
21             RedisClient client = new RedisClient(RedisPath);
22             client.Set<T>(key, value);
23             client.Save();
24             client.Dispose();
25         }
26 
27         public static void Set<T>(string key, T value, DateTime expiresAt)
28         {
29             RedisClient client = new RedisClient(RedisPath);
30             client.Set<T>(key, value, expiresAt);
31             client.Save();
32             client.Dispose();
33         }
34 
35         public static bool Remove(string key)
36         {
37             RedisClient client = new RedisClient(RedisPath);
38             bool isok = client.Remove(key);
39             client.Save();
40             client.Dispose();
41             return isok;
42         }
43     }
44 }

用主服务器的写入数据

用从服务器去获取数据

原文地址:https://www.cnblogs.com/shousiji/p/10194838.html