windows SEVER包:http://code.google.com/p/servicestack/wiki/RedisWindowsDownload

windows仅用来测试,性能不如在linux下高.

c#使用:

引用的ServiceStackRedis:https://github.com/mythz/ServiceStack.Redis

  1. static void Main(string[] args)
  2. {
  3. var Redis = new RedisClient("127.0.0.1", 6379);//redis服务IP和端口
  4. #region =insert=
  5. //var storeMembers = new List<string> { "jj", "lihui", "cc" };
  6. //storeMembers.ForEach(x => Redis.AddItemToList("additemtolist", x));
  7. //注:也可直接使用AddRangeToList方法将一组数据装入如:
  8. //Redis.AddRangeToList("additemtolist", storeMembers);
  9. #endregion
  10. #region =get=
  11. //var members = Redis.GetAllItemsFromList("additemtolist");
  12. //members.ForEach(s => Console.WriteLine("additemtolist :" + s));
  13. //Console.WriteLine(Redis.GetItemFromList("additemtolist", 2));
  14. #endregion
  15. #region =delete=
  16. //var list = Redis.Lists["additemtolist"];
  17. //list.Clear();//清空
  18. //list.Remove("two");//移除指定键值
  19. //list.RemoveAt(2);//移除指定索引位置数据
  20. #endregion
  21. #region =object=
  22. //Redis.Set("userinfo", new UserInfo() { UserName = "李四", Age = 45 });
  23. //UserInfo userinfo = Redis.Get<UserInfo>("userinfo");
  24. //Console.WriteLine(userinfo.UserName);
  25. //Redis.Set<int>("my_age", 12);//或Redis.Set("my_age", 12);
  26. //Console.WriteLine(Redis.Get<int>("my_age"));
  27. #endregion
  28. var ser = new ObjectSerializer();    //位于namespace ServiceStack.Redis.Support;
  29. #region =序列化=
  30. //bool result = Redis.Set<byte[]>("userinfo", ser.Serialize(new UserInfo() { UserName = "张三", Age = 12 }));
  31. //UserInfo userinfo = ser.Deserialize(Redis.Get<byte[]>("userinfo")) as UserInfo;
  32. //Console.WriteLine(userinfo.UserName);
  33. #endregion
  34. //也支持列表
  35. //Redis.Set<byte[]>("userinfolist_serialize", ser.Serialize(userinfoList));
  36. #region =负载均衡=
  37. PooledRedisClientManager prcm = CreateManager(new string[] { "10.0.4.210:6379" }, new string[] { "10.0.4.210:6379" });
  38. List<UserInfo> userinfoList = new List<UserInfo>();
  39. userinfoList.Add(new UserInfo() { UserName = "pool_daizhj", Age = 1 });
  40. userinfoList.Add(new UserInfo() { UserName = "pool_daizhj1", Age = 2 });
  41. // 从池中获取一个链接:
  42. using (IRedisClient Redis2 = prcm.GetClient())
  43. {
  44. Redis2.Set("userinfolist", userinfoList);
  45. List<UserInfo> userList = Redis2.Get<List<UserInfo>>("userinfolist");
  46. }
  47. #endregion
  48. Console.ReadLine();
  49. }
  50. public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts)
  51. {
  52. //支持读写分离,均衡负载
  53. return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig
  54. {
  55. MaxWritePoolSize = 5,//“写”链接池链接数
  56. MaxReadPoolSize = 5,//“写”链接池链接数
  57. AutoStart = true,
  58. });
  59. }

redis在.NET下的使用的更多相关文章

  1. redis 在linux下的安装

    背景:在项目互联网项目开发中我们经常需要缓存热点数据,在做热点数据缓存时有2个常用的方案 redis简介redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型 ...

  2. (转)NoSQL——Redis在win7下安装配置的学习一

    NoSQL——Redis在win7下安装配置的学习一   有些也是从网上看来的 1.下载安装 Redis它没有windows的官方版本,但是又非官方的版本,到官网上去下载相应的版本,我的电脑是win7 ...

  3. [傻瓜版] Redis在Windows下的开发环境配置步骤

    redis默认运行在unix体系下,windows无法直接运行官方版.以下是几种解决方案, 一)Windows移植版.启动速度飞快,优先推荐使用. a) 2.6.12 是稳定版,我用64位版来做开发环 ...

  4. redis入门(14)redis集群下的数据分区存储

    redis入门(10)redis集群下的数据分区存储

  5. 【Redis】windows下redis服务的安装

    下载地址: https://github.com/MicrosoftArchive/redis/releases Redis 支持 32 位和 64 位.这个需要根据你系统平台的实际情况选择,这里我们 ...

  6. redis 在Linux下的安装与配置

    redis在Linux下的安装与配置 by:授客  QQ:1033553122 测试环境 redis-3.0.7.tar.gz 下载地址: http://redis.io/download http: ...

  7. redis在Linux下的远程连接

    1.redis在Linux下的远程连接: $ redis-cli -h host -p port -a password 如何连接到主机为 127.0.0.1,端口为 6379 ,密码为 mypass ...

  8. Redis在windows下的配置

    Redis在windows下的配置(在windows-64下安装redis,请参考微软redis的github:https://github.com/MSOpenTech/redis/releases ...

  9. redis在Windows下以后台服务一键搭建哨兵(主从复制)模式(多机)

    redis在Windows下以后台服务一键搭建哨兵(主从复制)模式(多机) 一.概述 此教程介绍如何在windows系统中多个服务器之间,布置redis哨兵模式(主从复制),同时要以后台服务的模式运行 ...

  10. Redis在windows下安装过程(转)

    (转)原文:http://www.cnblogs.com/M-LittleBird/p/5902850.html 要使redis在PHP下运行, 需在PHP文件下的ext扩展文件夹中添加扩展文件 ph ...

随机推荐

  1. 开发设计模式(二) ActiveObject模式

    ActiveObject模式: ActiveObject模式和Command模式的配合使用是实现多线程控制的一项古老的技术,该模式有多种使用方式,为许多工业系统提供了一个简单的多任务核心. // 活动 ...

  2. C++学习笔记37:元编程

    元编程 什么是元编程(metaprogramming) 利用模板可以进行编译期计算(数值计算,型式计算和代码计算)的特点进行程序设计 为什么可以进行元编程? C++是两层语言:执行编译期计算的代码称为 ...

  3. 肾果手机App Store切换区域(无需Visa或者万事达)

    8月份在肾果官网买了个touch6,有时候需要换区去墙外下载app,然而一个个国家都要输入Visa或者万事达卡...今天终于找到一个不用输入信用卡号的区域:Canada!!! 办法(适用于8.X,7. ...

  4. javascript移动设备触屏事件

    ontouchstartontouchmoveontouchendontouchcancel 目前移动端浏览器均支持这4个触摸事件: /** * onTouchEvent */ var div = d ...

  5. C#如何控制方法的执行时间,超时则强制退出方法执行

    转自:http://outofmemory.cn/code-snippet/1762/C-how-control-method-zhixingshijian-chaoshi-ze-force-quit ...

  6. css3创建动画

    @keyframes ico{ 0% { top: -100%; } 100%{ top:4%; } } @-webkit-keyframes ico{ 0% { top: -100%; } 100% ...

  7. bzoj 4004: [JLOI2015]装备购买 拟阵 && 高消

    4004: [JLOI2015]装备购买 Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 337  Solved: 139[Submit][Status ...

  8. UVA 11734 Big Number of Teams will Solve This

    大水题,不解释啦! #include<cstdio> #include<cstring> #define maxn 50 using namespace std; char s ...

  9. Unity C#写的A*寻路

    原地址:http://www.unity蛮牛.com/blog-13769-1078.html 首先看了这篇翻译外国人的文章http://www.raywenderlich.com/zh-hans/2 ...

  10. Docker 监控- Prometheus VS Cloud Insight

    如今,越来越多的公司开始使用 Docker 了,2 / 3 的公司在尝试了 Docker 后最终使用了它.为了能够更精确的分配每个容器能使用的资源,我们想要实时获取容器运行时使用资源的情况,怎样对 D ...