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);
}
}
}
}

运行结果:
Redis Server分布式缓存编程的更多相关文章
- C# Redis Server分布式缓存编程 --网络转载
这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. 背景介绍 Redis是最快的key-value分布式缓存之一 缺点: 没有本地数据缓冲, 目前还没 ...
- C# Redis Server分布式缓存编程(一)(转)
出处:http://www.cnblogs.com/davidgu/p/3262571.html 这篇文章我将介绍如果用最简洁的方式配置Redis Server, 以及如何使用C#和它交互编程 一. ...
- C# 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实现分布式缓存
AspNetCore 使用Redis实现分布式缓存 上一篇讲到了,Core的内置缓存:IMemoryCache,以及缓存的基础概念.本篇会进行一些概念上的补充. 本篇我们记录的内容是怎么在Core中使 ...
- 【转载】在AspNetCore 中 使用Redis实现分布式缓存
原文地址:https://www.cnblogs.com/szlblog/p/9045209.html AspNetCore 使用Redis实现分布式缓存 上一篇讲到了,Core的内置缓存:IMemo ...
- ASP.NET Core 使用 Redis 实现分布式缓存:Docker、IDistributedCache、StackExchangeRedis
ASP.NET Core 使用 Redis 实现分布式缓存:Docker.IDistributedCache.StackExchangeRedis 前提:一台 Linux 服务器.已安装 Docker ...
- WEB 应用缓存解析以及使用 Redis 实现分布式缓存
什么是缓存? 缓存就是数据交换的缓冲区,用于临时存储数据(使用频繁的数据).当用户请求数据时,首先在缓存中寻找,如果找到了则直接返回.如果找不到,则去数据库中查找.缓存的本质就是用空间换时间,牺牲数据 ...
随机推荐
- oracle 存储过程,存储函数,包,
http://heisetoufa.iteye.com/blog/366957 认识存储过程和函数 存储过程和函数也是一种PL/SQL块,是存入数据库的PL/SQL块.但存储过程和函数不同于已经介绍过 ...
- CF161D Distance in Tree 点分治
题目: 输入点数为N一棵树,求树上长度恰好为K的路径个数 分析: 题目的数据范围不是很紧,点分治也可以过,树形dp也可以过.这里采用点分治做法. 我们只需要单开一个类似于桶的数组,跑点分治套路,统计即 ...
- 深入Linux内核架构——进程虚拟内存
逆向映射(reverse mapping)技术有助于从虚拟内存页跟踪到对应的物理内存页: 缺页处理(page fault handling)允许从块设备按需读取数据填充虚拟地址空间. 一.简介 用户虚 ...
- tiny4412u-boot烧写及根文件系统制作(不进入终端问题)
http://m.blog.csdn.net/article/details?id=51400196(转) VMware12 环境:ubuntu12.4 开发板:tiny4412 首先烧写bootlo ...
- Spring Boot 返回Html界面
@Controller public class HelloController { @RequestMapping("/") public String index(){ ret ...
- exports和moudle. exports
http://zihua.li/2012/03/use-module-exports-or-exports-in-node/ https://github.com/seajs/seajs/issues ...
- python3--算法基础:二分查找/折半查找
算法基础:二分查找/折半查找 #!/usr/bin/env python # -*- coding:utf-8 -*- # 算法基础:二分查找/折半查找 def binarySearch(dataSo ...
- python007 Python3 数字(Number)
var1 = 1 var2 = 10 您也可以使用del语句删除一些数字对象的引用.del语句的语法是: del var1[,var2[,var3[....,varN]]]] 您可以通过使用del语句 ...
- Android渲染器Shader:梯度渐变扫描渲染器SweepGradient(二)
Android渲染器Shader:梯度渐变扫描渲染器SweepGradient(二) 附录文章1介绍了线性渐变渲染器. Android的SweepGradient梯度渐变扫描,重点是在构造Swe ...
- BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~
jrMz and angle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...