这篇文章我将介绍如果用最简洁的方式配置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分布式缓存编程的更多相关文章

  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. C# 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. python3 yum not found

    vi /urs/bin/yum 将#!/usr/bin/python的python改为python2.x(你系统的python2的版本)

  2. xcode中自定义log打印

    打印内容包括 在哪个文件中 ? 在哪个方法中? 将要执行什么操作?   // 此打印实现前提: // 1.在.pch文件中实现自定义log打印方法,log名换为LCLog // 2.定义一个宏obje ...

  3. 前端拖动div 效果

    /** * author levi * url http://levi.cg.am */ $(function() { $(document).mousemove(function(e) { if(! ...

  4. Node.js实现简单的爬取

    学习[node.js]也有几天时间了,所以打算写着练练手:索然我作为一个后端的选手,写起来还有那么一丝熟悉的感觉.emmm~~  ‘货’不多讲 ,开搞........ 首先是依赖选择: 代码块如下: ...

  5. luogu P4752

    给定一个数字 A ,这个 A 由 a1,a2,...,aN 相乘得到. 给定一个数字 B ,这个 B 由 b1,b2,⋯,bM 相乘得到. 如果 A/B​ 是一个质数,请输出YES,否则输出NO. 输 ...

  6. linux shell 搭建本地yum 源,通过IOS镜像 Centeros6,7还有redhat

    Centeros: 准备工作: 将系统镜像放到 /opt 下 脚本: #!/bin/bash mkdir /mnt/cdrom mount -o loop /opt/*.ios;# 此处改为你的系统镜 ...

  7. 杭电 4707 pet(并查集求元素大于k的集合)

    Description One day, Lin Ji wake up in the morning and found that his pethamster escaped. He searche ...

  8. Laya Tween 和 遮罩

    Laya Tween 和 遮罩 @author ixenos 场景:在使用Tween循环时,不规则物体部分超出范围 方案:使用遮罩定型 困境:在laya ide设计模式中将遮罩sprite放到不规则物 ...

  9. ERP类系统设计学习

    文章:分布式.服务化的ERP系统架构设计 文章的方法是对系统进行拆分,拆分成多个子系统.

  10. [HNOI2012] 永无乡 题解

    题意: n个点,有加边操作,询问与某一点处于相同的联通块的点中权值第k大的点 思路: 对所有点建立一棵权值线段树,加边就配合并查集进行线段树合并 反思: 动态开点,权值线段树要用sum[g[x=fin ...