这篇文章我将介绍如果用最简洁的方式配置Redis Server,

以及如何使用C#和它交互编程

一. 背景介绍

Redis是最快的key-value分布式缓存之一

缺点: 没有本地数据缓冲, 目前还没有完整的数据聚集化支持

优点: 配置简单, 使用方便, 高性能,支持不同的数据类型(hashes, lists, sets, sorted sets)

ASP.NET WebUI for viewing content of the cache

二. 安装Redis

1) 从github下载最新的32/64位安装

https://github.com/dmajkic/redis/downloads

解压到你自己的目录

eg: d:\RedisServer

2) 从github下载Redis服务程序

dll手工版

https://github.com/kcherenkov/redis-windows-service/downloads

安装版

https://github.com/rgl/redis/downloads

拷贝到RedisServer的安装目录

eg: d:\RedisServer

3) 安装redis服务

进入你的应用程序目录,运行下面的命令

sc create %name% binpath= "\"%binpath%\" %configpath%" start= "auto" DisplayName= "Redis"

%name% -- name of service instance, ex. redis-instance;

%binpath% -- path to this project exe file, ex. C:\Program Files\Redis\RedisService_1.1.exe;

%configpath% -- path to redis configuration file, ex. C:\Program Files\Redis\redis.conf;

sc create my-redis binpath= "\"D:\RedisServer\RedisService_1.1.exe\"  D:\RedisServer\redis.conf" start= "auto" DisplayName= "MyRedis"

4) 基本配置

redis.conf

# requirepass foobared

去掉注释,重启服务

这样实例化一个Redis服务的时候,就需要密码

RedisClient client = new RedisClient(serverHost, port, redisPassword);

Redis server replication (master - slave配置)

# slaveof <masterip> <masterport>

eg:

slaveof 192.168.1.1 6379

三. 客户端编程

1) 安装Redis包

2) 简单例子

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.Redis;
using System.Threading; namespace Zeus.Cache.Redis.Demo
{
public class SimpleRedisDemo
{
public void SimpleDemo()
{
string host = "localhost";
string elementKey = "testKeyRedis"; using (RedisClient redisClient = new RedisClient(host))
{
if (redisClient.Get<string>(elementKey) == null)
{
// adding delay to see the difference
Thread.Sleep(2000);
// save value in cache
redisClient.Set(elementKey, "default value");
} //change the value
redisClient.Set(elementKey, "fuck you value"); // get value from the cache by key
string message = "Item value is: " + redisClient.Get<string>(elementKey); Console.WriteLine(message);
}
}
}
}

运行结果:

C# Redis Server分布式缓存编程 --网络转载的更多相关文章

  1. C# Redis Server分布式缓存编程(一)(转)

    出处:http://www.cnblogs.com/davidgu/p/3262571.html 这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. ...

  2. C# Redis Server分布式缓存编程(一)

    这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...

  3. Redis Server分布式缓存编程

    这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...

  4. C# Redis Server分布式缓存编程(二)

    在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Redis.Demo { public class Person { public int Id { g ...

  5. C# Redis Server分布式缓存编程(二)(转)

    出处;http://www.cnblogs.com/davidgu/p/3263485.html 在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Red ...

  6. 【转载】在AspNetCore 中 使用Redis实现分布式缓存

    原文地址:https://www.cnblogs.com/szlblog/p/9045209.html AspNetCore 使用Redis实现分布式缓存 上一篇讲到了,Core的内置缓存:IMemo ...

  7. 在AspNetCore 中 使用Redis实现分布式缓存

    AspNetCore 使用Redis实现分布式缓存 上一篇讲到了,Core的内置缓存:IMemoryCache,以及缓存的基础概念.本篇会进行一些概念上的补充. 本篇我们记录的内容是怎么在Core中使 ...

  8. ASP.NET Core 使用 Redis 实现分布式缓存:Docker、IDistributedCache、StackExchangeRedis

    ASP.NET Core 使用 Redis 实现分布式缓存:Docker.IDistributedCache.StackExchangeRedis 前提:一台 Linux 服务器.已安装 Docker ...

  9. WEB 应用缓存解析以及使用 Redis 实现分布式缓存

    什么是缓存? 缓存就是数据交换的缓冲区,用于临时存储数据(使用频繁的数据).当用户请求数据时,首先在缓存中寻找,如果找到了则直接返回.如果找不到,则去数据库中查找.缓存的本质就是用空间换时间,牺牲数据 ...

随机推荐

  1. C#基础知识汇总

    过了一遍基础视频,发现有一些最基本的知识点还掌握的不够,汇总如下: 1) 占位符 string name = "张三"; ; decimal salary = 7600.33M; ...

  2. .Net中使用com组件后发生System.ArithmeticException异常的解决办法(Message=算术运算中发生溢出或下溢。)

    最近在开发一个.Net程序,其中涉及到对com组件的调用,或者第三方DLL调用, 在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序,或者WPF程序中,继续执行 ...

  3. 史上最简单的socket

    1. client import java.io.IOException; import java.io.OutputStream; import java.net.Socket; import ja ...

  4. sync_with_stdio

    /* The synchronization referred to is @e only that between the standard * C facilities (e.g., stdout ...

  5. Java 和 C+

    文不对题,啦啦啦~~~ 第一次感到在windows平台java应用发布的无力,平时自己自写自用都是在自己电脑上,没什么感觉.如今要发布个给人用,打包应用.附加jre,这过程还得多加几行字说明,另人特么 ...

  6. 如何在Form++开源组态平台添加硬件采集接口

    E-Form++是一套值得推荐的高品质开源C++矢量图形库,C++编程之所以异常困难,主要就是没有很专业的C++基础架构库有关.E-Form++的出现一定程度上填补了这个空白.是开发工控.监控.建模与 ...

  7. WordPress使用记录

    主要记录WordPress4.7使用过程中遇到的一些问题及解决办法. 1.无法显示主题列表 问题:新的版本主题管理页面是只显示当前主题的,无法进行管理. 解决:修改php.ini文件,参考这里.

  8. MySql的max_connections和max pool的设置

    这几天工作当中,在使用mysql数据库的时候,碰到了too many connections的问题和timeout expired的问题,经过尝试,稍作总结,希望能够帮到需要的朋友; 在测试当中发现, ...

  9. win10 64位 mysql安装

    一.安装mysql 1.下载mysql-5.7.15-winx64.zip http://dev.mysql.com/downloads/mysql/ 2.解压缩到D:\ProgramFiles 3. ...

  10. C# 字符编码解码 Encoder 和Decoder

    在网络传输和文件操作中,如果数据量很大,需要将其划分为较小的快,此时可能出现一个数据块的末尾是一个不匹配的高代理项,而与其匹配的低代理项在下一个数据块. 这时候使用Encoding的GetBytes方 ...