C# Redis Server分布式缓存编程 --网络转载
这篇文章我将介绍如果用最简洁的方式配置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分布式缓存编程 --网络转载的更多相关文章
- C# Redis Server分布式缓存编程(一)(转)
出处:http://www.cnblogs.com/davidgu/p/3262571.html 这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. ...
- C# Redis Server分布式缓存编程(一)
这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...
- Redis Server分布式缓存编程
这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...
- C# Redis Server分布式缓存编程(二)
在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Redis.Demo { public class Person { public int Id { g ...
- C# Redis Server分布式缓存编程(二)(转)
出处;http://www.cnblogs.com/davidgu/p/3263485.html 在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Red ...
- 【转载】在AspNetCore 中 使用Redis实现分布式缓存
原文地址:https://www.cnblogs.com/szlblog/p/9045209.html AspNetCore 使用Redis实现分布式缓存 上一篇讲到了,Core的内置缓存:IMemo ...
- 在AspNetCore 中 使用Redis实现分布式缓存
AspNetCore 使用Redis实现分布式缓存 上一篇讲到了,Core的内置缓存:IMemoryCache,以及缓存的基础概念.本篇会进行一些概念上的补充. 本篇我们记录的内容是怎么在Core中使 ...
- ASP.NET Core 使用 Redis 实现分布式缓存:Docker、IDistributedCache、StackExchangeRedis
ASP.NET Core 使用 Redis 实现分布式缓存:Docker.IDistributedCache.StackExchangeRedis 前提:一台 Linux 服务器.已安装 Docker ...
- WEB 应用缓存解析以及使用 Redis 实现分布式缓存
什么是缓存? 缓存就是数据交换的缓冲区,用于临时存储数据(使用频繁的数据).当用户请求数据时,首先在缓存中寻找,如果找到了则直接返回.如果找不到,则去数据库中查找.缓存的本质就是用空间换时间,牺牲数据 ...
随机推荐
- what we do and how we behave
It comes after a report last week revealed the "brutal" treatment of terror suspects by th ...
- String类常用方法小节
(1)String.equals() 返回值是boolean类型 equals(Object anObject) 将此字符串与指定的对象比较. (2)length() 返回值是in ...
- zepto插件 countdown 倒计时插件 从jquery 改成 zepto
插件特色:支持zepto库 支持时间戳格式 支持年月日时分秒格式 countdown 由jquery依赖库改成zepto zepto的event机制与jquery不同,所以更换之后代码不能正常运行 ...
- rand & random & arc4random
rand(3) / random(3) / arc4random(3) / et al. Written by Mattt Thompson on August 12th, 2013 What pas ...
- 如何全面解决ECSHOP的jquery冲突
主要就是Ecshop的AJAX传输类,transport.js中重写了object的对象原型,从而导致了与jq框架的冲突. 解决: 1. 删除transport.js中587行 - 636行中关于ob ...
- IOS 更改百度地图的定位图片
使用了百度地图的SDK,定位图片一直是蓝色的小圆点,很不喜欢,想换成自定义的图片,在网上搜罗了一大通,找到了解决的方案. 写下如下代码: //定位图层自定义样式参数 BMKLocationViewDi ...
- 获得触发hover事件的元素id
例: <div class="menu"> <ul> <li> <a id="menu1"></a> ...
- Linux的课程总结
Linux的课程总结 20125133 马国祥 通过16周的学习明白学好linux不是一件一蹴而就的事,一定要能坚持使用它,特别是在使用初期,由于在linux中,用户权限很大,做任何事情都很自由,所以 ...
- B - Dividing
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Status Descr ...
- Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)
实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...