概述Redis是一个开源的、使用C语言编写的、支持网络交互的、可基于内存也可持久化的Key-Value(字典, Remote Dictionary Server,远程字典服务器)数据库。 客户端:http:///clients .NET开发程序配置
程序配置Redis服务IP和端口 static RedisClient Redis = new RedisClient("192.168.100.118", 6379); 双击运行:redis-server.exe Redis Desktop Manager 介绍Redis Desktop Manager(RedisDesktopManager,RDM)是一个快速、简单、支持跨平台的 Redis 桌面管理工具,基于 Qt 5开发(一个跨平台的C++图形用户界面应用程序框架),支持通过 SSH Tunnel 连接。 下载地址:http:///download 配置Redis服务地址: 查看可视化keys的值: C#操作5种基本数据类型1. 字符串A: 存储普通字符串,并设置过期时间 B: 存储类对象 测试用例输出结果: 2. 哈希存储: client.SetEntryInHash("HashID", "Name", "张三"); A: 遍历HashID值为HashID的keys 获取:List<string> HaskKey = client.GetHashKeys("HashID"); B:遍历HashID值为HashID的values 获取:List<string> HaskValue = client.GetHashValues("HashID"); C:遍历所有keys 获取:List<string> AllKey = client.GetAllKeys(); 测试用例输出结果: 3. 链表A: 队列 B: 栈 出栈:client.PopItemFromList("StackListId") 测试用例输出: 4. 无序集合存储: client.AddItemToSet("SetA", "1"); 获取:HashSet<string> setA = client.GetAllItemsFromSet("SetA"); A:并集 HashSet<string> hashUnion = client.GetUnionFromSets(new string[] { "SetA", "SetB" }); B:交集 HashSet<string> intersectSet = client.GetIntersectFromSets(new string[] { "SetA", "SetB" }); C:差集 HashSet<string> setOfDiffSetAToSetB = client.GetDifferencesFromSet("SetA", new string[] { "SetB" }); 测试用例输出: 5. 有序集合存储:client.AddItemToSortedSet("SetSorted", "A"); 输出:List<string> listSetSorted = client.GetAllItemsFromSortedSet("SetSorted"); 测试用例输出: Redis应用场景只是介绍我本人在使用Redis时用到的场景,仅个人观点。 A.抢XXX赠券、抽奖系统的奖品库存,使用的Redis中的链表前一天晚上通过定时服务推送奖品库存,使用LPUSH命令将乱序的奖品推入List中,抽奖时则调用LPOP命令,将最左侧奖品弹出队列,提示用户中奖。同时,发送异步消息,让消息去处理中奖纪录并插入关系型数据库中。
|
|
来自: WindySky > 《redis应用场景》