zoukankan      html  css  js  c++  java
  • 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 }

    用主服务器的写入数据

    用从服务器去获取数据

  • 相关阅读:
    php -- 读取大文件
    php header函数下载文件实现代码
    HTTP HEADER 详解
    linux -- 进程管理和作业控制
    linux -- at命令
    Binary String Matching
    括号匹配
    ASCII码排序
    快捷键
    ubuntu14的unity desktop显示异常
  • 原文地址:https://www.cnblogs.com/shousiji/p/10194838.html
Copyright © 2011-2022 走看看