这篇文章我将介绍如果用最简洁的方式配置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();
// 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分布式缓存编程 --网络转载

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

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

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

  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实现分布式缓存

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

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

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

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

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

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

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

随机推荐

  1. 关闭vscode打开新文件自动关闭预览文件功能

    经常碰到这个问题,我打开文件就是有用的,每次给我自动关闭了我还得去打开. 当然这个问题可以双击文件,接触那个文件的预览状态就可以解决了.不过还有一个更懒的方法,直接修改vscode配置就好了. // ...

  2. placeholer改变默认灰色

    input::-webkit-input-placeholder,textarea::-webkit-input-placeholder{ color:#7b642c; } input:-moz-pl ...

  3. python自动化测试windows gui

    http://sourceforge.net/projects/pywinauto/files/pywinauto/ http://www.microsoft.com/en-us/download/c ...

  4. Linux内核之页面换出详解

    kswap线程主要用于页面的定期换出,接下来说说kswap线程的实现 首先kswap线程的初始化时,需要根据物理内存的大小设置一个page_cluster变量的值,这个值表示预读数目 (比如本来只读一 ...

  5. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/ColorRes.class

    保存信息如上: 我在添加一个支持库的时候遇的问题,这个库com.yanzhenjie:album:1.0.5 这是由于v4包重复导致的,在网上我也找过多种解决方案   用了这种,方式 configur ...

  6. mysql 共享空间转为独立表空间

    由于以前的mysql配置为共享表空间,服务器空间不足,清理日志表里的数据后,数据库并没缩小,照成空间浪费,现在修改为独立表空间 #独立表空间innodb_file_per_table=1 #停止事物日 ...

  7. poj 1329(已知三点求外接圆方程.)

    Circle Through Three Points Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3766   Acce ...

  8. [BZOJ1032][JSOI2007]祖码Zuma 区间dp

    1032: [JSOI2007]祖码Zuma Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 1105  Solved: 576 [Submit][S ...

  9. 树的直径【p3629】[APIO2010]巡逻

    Description 在一个地区中有 n 个村庄,编号为 1, 2, ..., n.有 n – 1 条道路连接着这些村 庄,每条道路刚好连接两个村庄,从任何一个村庄,都可以通过这些道路到达其 他任一 ...

  10. Mycat查询时出现:Error Code: 1064. can't find any valid datanode

    说明:这个错误是查询时条件字段超过了范围导致的. 解释: 为什么会出现范围问题? 一般在MySQL查询时不会因为字段的值超过了范围而导致的,但是在Mycat中却不是这样认为的,Mycat是由于采用的分 ...