码迷,mamicode.com
首页 > Windows程序 > 详细

Windows版Redis主从配置

时间:2018-12-29 11:55:42      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:出现   rem   key   git   nbsp   span   主从   ima   datetime   

一、下载

从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 }

用主服务器的写入数据

技术分享图片

 

用从服务器去获取数据

技术分享图片

 

Windows版Redis主从配置

标签:出现   rem   key   git   nbsp   span   主从   ima   datetime   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!