下载 redis windows 版本 官网目前没有windows安装下载,下载地址为

https://github.com/MicrosoftArchive/redis/releases

直接点击安装 一直下一步

我的安装路径  D:\Program Files\Redis

启动命令行工具 测试redis

C#  连接redis 在项目类库引用上右键启动NuGet 搜索redis 安装以下二个框架

redis工具类

public class RedisCacheHelper
{
private static readonly PooledRedisClientManager pool = null;
private static readonly string[] redisHosts = null;
public static int RedisMaxReadPool = ;
public static int RedisMaxWritePool = ; static RedisCacheHelper()
{
var redisHostStr = "127.0.0.1:6379"; if (!string.IsNullOrEmpty(redisHostStr))
{
redisHosts = redisHostStr.Split(','); if (redisHosts.Length > )
{
pool = new PooledRedisClientManager(redisHosts, redisHosts,
new RedisClientManagerConfig()
{
MaxWritePoolSize = RedisMaxWritePool,
MaxReadPoolSize = RedisMaxReadPool,
AutoStart = true
});
}
}
} #region Add
public static void Add<T>(string key, T value, DateTime expiry)
{
if (value == null)
{
return;
} if (expiry <= DateTime.Now)
{ Remove(key); return;
} try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
r.Set(key, value, expiry - DateTime.Now);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "存储", key);
} } public static void Add<T>(string key, T value, TimeSpan slidingExpiration)
{
if (value == null)
{
return;
} if (slidingExpiration.TotalSeconds <= )
{
Remove(key); return;
} try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
r.Set(key, value, slidingExpiration);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "存储", key);
}
} public static T Get<T>(string key)
{
if (string.IsNullOrEmpty(key))
{
return default(T);
} T obj = default(T); try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
obj = r.Get<T>(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "获取", key);
} return obj;
}
#endregion public static void Remove(string key)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
r.Remove(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "删除", key);
} } public static bool Exists(string key)
{
try
{
if (pool != null)
{
using (var r = pool.GetClient())
{
if (r != null)
{
r.SendTimeout = ;
return r.ContainsKey(key);
}
}
}
}
catch (Exception ex)
{
string msg = string.Format("{0}:{1}发生异常!{2}", "cache", "是否存在", key);
} return false;
}
}

测试操作

测试

C# 操作redis的更多相关文章

  1. Java Spring mvc 操作 Redis 及 Redis 集群

    本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5941953.html 关于 Redis 集群搭建可以参考我的另一篇文章 Redis集群搭建与简单使用 R ...

  2. Java中使用Jedis操作Redis(转载)

    整理 1.字符串 添加:set keyname value 查询:get keyname 拼接:append keyname value 删除:del keyname 添加多个: mset keyna ...

  3. (转)Java中使用Jedis操作Redis

    转自http://www.cnblogs.com/liuling/p/2014-4-19-04.html 使用Java操作Redis需要jedis-2.1.0.jar,下载地址:http://file ...

  4. Python—操作redis

    Python操作redis 连接方式:点击 1.String 操作 redis中的String在在内存中按照一个name对应一个value来存储 set() #在Redis中设置值,默认不存在则创建, ...

  5. php操作redis简单例子

    <?php //在PHP里操作Redis //Redis就是php的一个功能类 //创建Redis对象 $redis = new Redis(); //链接redis服务器 $redis -&g ...

  6. python——操作Redis

    在使用django的websocket的时候,发现web请求和其他当前的django进程的内存是不共享的,猜测django的机制可能是每来一个web请求,就开启一个进程去与web进行交互,一次来达到利 ...

  7. 使用jedis操作redis

    一 连通性 1. 简单代码测试连通性 Jedis jedis = new Jedis(".......", 6379); String keys = "name" ...

  8. Java中使用Jedis操作Redis

    使用Java操作Redis需要jedis-2.1.0.jar,下载地址:http://files.cnblogs.com/liuling/jedis-2.1.0.jar.zip 如果需要使用Redis ...

  9. Python操作Redis、Memcache、RabbitMQ、SQLAlchemy

    Python操作 Redis.Memcache.RabbitMQ.SQLAlchemy redis介绍:redis是一个开源的,先进的KEY-VALUE存储,它通常被称为数据结构服务器,因为键可以包含 ...

  10. 通过PHP扩展phpredis操作redis

    我们使用phpredis,这个扩展能让你用PHP操作redis. 源码下载: phpize ./configure ); var_dump($result); echo $redis->get( ...

随机推荐

  1. input.nextLine()的注意事项

    若在input.nextInt()和input.nextDouble()后使用input.nextLine(),要先加一个input.nextLine()进行换行

  2. PostMan Test 的脚本scripts编写方法

    设置环境变量 pm.environment.set("variable_key", "variable_value"); 将一个嵌套的对象设置为一个环境变量 v ...

  3. C#参考教程 http://www.csref.cn

    推荐 C#参考教程 http://www.csref.cn

  4. Failed to load ApplicationContext ,Error creating bean with name 'adminUserService': Injection of autowired dependencies failed;

    Druid配置的时候出现这个问题: "C:\Program Files\Java\jdk1.8.0_191\bin\java" -ea -Didea.test.cyclic.buf ...

  5. eclipse启动tomcat错误解决

    clipse启动tomcat报出下面的错误提示: 控制台: 九月 06, 2018 9:01:31 下午 org.apache.tomcat.util.digester.SetPropertiesRu ...

  6. JMeter在linux服务器上使用

    环境部署: 1.在Linux服务器先安装jdk:此步骤省略,可参考百度经验:https://jingyan.baidu.com/article/6b18230980c294ba59e15967.htm ...

  7. mongoDB数据库的安装与配置

    noSql数据库MongoDB的安装地址:https://www.mongodb.com/download-center?jmp=nav#community 选择相应的版本进行下载,在此以window ...

  8. 软件测试_Fiddler抓包工具二

    多数资料摘至:https://www.cnblogs.com/nihaorz/p/5455148.html Fiddler 的命令使用 如何打开命令行:左下方的小黑条命令行,点击它就可以输入命令了(a ...

  9. 【开发】iOS入门 - UIViewController学习笔记

    iOS里面的UIViewController类似于Android里的Activity. 目前了解到除了基本的UIViewController之外,还有两个比较特别的一个是UINavigationCon ...

  10. MySQL命令行登陆,远程登陆MySQL 的方法

    https://www.cnblogs.com/lvk618/p/3522321.html 1.MySQL自带工具的存放路径: D:\Program Files\MySQL\MySQL Server ...