Redis学习笔记~关于空间换时间的查询案例
空间与时间
空间换时间是在数据库中经常出现的术语,简单说就是把查询需要的条件进行索引的存储,然后查询时为O(1)的时间复杂度来快速获取数据,从而达到了使用空间存储来换快速的时间响应!对于redis这个k/v存储系统来说,复杂的查询不是它所建议的,它的优势在于通过key快速定位数据,它定位数据的速度与数据多少没有直接关系,无论是1万还是1亿数据,它定位的时间复杂度都是O(1),而在实际使用中,可能不简单使用key定位数据就够了,可能还需要数据里的某个属性去定位数据,这种情况第一感觉不能用redis,或者说,不能用k/v存储系统了,但这不是我们应该说的,我们要的是解决方案,换个角度去思考,我们是否可以把那个属性拿出来当新的key,把原来的key当作它的value呢,答案是肯定的,这就是用空间到换时间,只需要两个查询就可以搞定了!
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAiYAAAEECAIAAACTIGixAAAgAElEQVR4nO1dPY40SRGty3ACLoCDsBYJAwMHF+FxBA7APfA5BUhrLGglcBBCwgMJY3cbZ2cLo6G+nIyffBmVlRXZ855KPdXZkREvXmZk9Mz0N9+2E0Q/3r756m+/+PE/f/r9f//oe//41c/+85c/7d+97d+9/ecvf/rHr3727x99758//f7ffvHjt2++OqZ8/vnnNxImCCIDtrsJEGvi7e3rL/7w15//8O+//Mnjz3/87ttvn8Pfffvt489//Psvf/LXn//w6y/+sL+9HTPYcgiCYMshonh7e/v6q7dvvt6/e3s3/t3b2zdfv339VdlvdrYcgiDYcohpYMshCIIth5gEthyCINhyiElgyyEIgi2HmAS2HIIg2HKISficIIgPD7YcYhL+9a9/3U2BIIibwZZDEARBTAJbDkEQBDEJbDkEQRDEJLDlEARBEJPAlkMQBEFMAlsOQRAEMQlsOQRBEMQksOUQBEEQk8CWQxAEQUwCWw5BEAQxCWw5BEEQxCSw5RAEQRCTwJZDEARBTMJtLefXBEEQd+OuA/DD4s6W8wOCIIj78OUXv7/rAPywuLnl3BWdIAiCLWc+2HIIgvigYMuZD7YcgiA+KNhy5oMthyCIDwq2nPn4X8vZ/o/f/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fvaXlBAjHMGpREooJcuvF2DKbg64efO9iSeQ5YeX4eW6BWXkESVIL27ZBP1hrjk+A9aYYp+oUnuW/yQd5tQxxoEqhsnloqcXqR5Uom5hqoPO6lTSkN+nc8e8QBm3wuKomCRfLD91cGpkCuAqbDYTPo5WspW1AojyClKtsBXXmWppIGm0bvOUEFB8IJ21/q8kRZx+AOSLKVvdWUIsJ4hMho3pLJabv+Yxusswcb00zizC+GZq5qOHSLpbKR/VWjfjy4nJZGjYDxdY0tp+TCJKkFh4P7OMDzWBXA1ySgEGvrKAZfibKTTm2fnA/6sgcMX1uYd2cypETq0frsAgDPMWa8oLGoLcziyWBbN1m0Grdkeq4umTCs/IIkqcW/guriou5v5UFaAAAAABJRU5ErkJggg==" alt="" />
上面是一个100万的hash集合,key是用户id,value是一个用户实体,我们通过RedisClient.RedisManager.Instance.GetDatabase().HashGet("VoteList", id)很方便的可以拿到对应的用户实体!
我希望通过用户名拿到用户实体?
这种需求,我们不要直接解决,如果直接解决,那唯一的办法就是遍历所有数据,然后一一对比,时间复杂度就是O(N),太可怕了!
通过添加新的k/v,解决这个问题,这类似于关系数据库里的全表扫描+索引技术!
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgsAAAEXCAIAAACswZDkAAAT7klEQVR4nO3dQZarOLIAUJZWS+sF9D5qKzX4gxrUMnqcU//Be+XEKBQSgjQi896j04eUhZCpEIGwX3t5wPfyf8BJlqunM5zsf//739VDgG9ChgAgJkMAEJMhAIjJEADEZAgAYjIEADEZAoCYDAFATIYAICZDABCTIQCIyRAAxGQIAGJvzRD/AbjaOy96d/fuDPEHwHX++fuvd1707u6CDPHOIwKsyRC7yBDADyJD7CJDAD+IDLGLDAH8IDLELsuyLP/973+Xld+1y7JtVyh3zK0zRHm4nh7ab6bez/H+wwN9xeDP6hPYGM4Q4bXuDZO0dinOK89q9vnaul3Yy2bnWuPEZg2x60R3HuKUK/XeZmdFyeasntInsDaWId6cFdbHqh06vFY8L+tnNQsu9Muy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Bp2SIOacztzN1huh/0NT8bDn8M6zJe0gqYVhnANcqx+Icml6+V7cJzfDD3rcpP5cua5qVYYdJTVnZf1A4Yiw+85p87kCTWAEgJkMAEJMhAIjJEADEZAgAYn5BCICYDAFA7DNDLMtLtnh+dfrtQ9onHGcy+LJl3uHmi+SdR4G9auHUrCl3rAWtiGWvl+vgZ21le1qdgw8nTN7POlWELW9xfphcEsDNGC63w+AUsQxoX1hvEU+1QSZX/HDHPLs0DwfHbS7l+RoiD0tZgYPaV72rYqtcKdfWzuEga7daJ2YIC3bOtY6o5OI+nCFELHs1MsSF8ZRMlXzOdHbS/LPzaZUpx7nyx5sfe6J0vS1iGdB1A3KhzlHlGaJzFiUtPXHibWrL37BmIEpFLP16L51XOSVDfLw+oUp2lCG4XPlMNWyQb/c3g8TUMdT/oGngyeyRfiY8V9xa/zI3aSxDcLrtLfbmz/AW5k0jK8YQjiqvrPWZNKtV5l3BQZ3R2FPzrG/2DznhAkBMhgAgJkMAEJMhAIjJEADE/IIQADEZAoDYZ4ZYlpds8fz29NuHtE9tnEl9s80jOhud/cOwMKg6J2azRsQy4He4bEKntj2t2qQKJ0n5UtKs/DPfF8bUIrNnYoYheusZzSTacXOLeOqZAL/qmxli0yzvM38JOiUL2eaFPozYWp9JPZSyC+u1a9LlVVizbrzZrt1DJVMxaVbby2TjFGXQ5hH7KBJDT4YQsew17xoimSr5ZMinWXPfsJk1BF+qDNqD9zS1HZN6KM2bIWpHzydMuJ08g+p8VitD8KVqtziPdAp0Nuush9KPyBCP1ydUeefNp1g944Fdao9Jm6FYa1a2bNZDqetrEm8d0Ur/w6L+weeL99qOnYeDMQPL3KSHfEcRS7/tLfbnC5Ubk7dZXoU1zcpan7Udw9172sBBu0KxOVt7aqBJuAAQkyEAiMkQAMRkCABiMgQAMb8gBEBs+efvvxRFURSlLP8PwJeHcjoSr8gAAAAASUVORK5CYII=" alt="" />
实现程序:先通过userName找到UserId,再通过UserId找到用户实体!
[TestMethod]
public void FindBigData()
{
Stopwatch sw = new Stopwatch();
sw.Start();
var name = RedisClient.RedisManager.Instance.GetDatabase().HashGet("VoteList_UserName", "zzl15");//找到用户ID
if (name.HasValue)
{
var val = RedisClient.RedisManager.Instance.GetDatabase().HashGet("VoteList", name);//找到用户实体
Console.WriteLine("name={0},value={1}", name, val);
}
else
{
Console.WriteLine("没有发现这个Key");
}
sw.Stop();
Console.WriteLine("查询需要的时间:" + sw.ElapsedMilliseconds + "ms");
}
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAvEAAAB7CAIAAABy7kghAAARgElEQVR4nO3dz8skxR3Hcf+S/ieWgT15Ug/ts0c9+oDgRVhknnFPejJ7E7zYDkgkIfKYQwKa0I4biUhcCImshx0mS9TkkAxRgopL3N0OgsQcaqamuupb1TX9Y2aemveLZZnp6a6uqunp/kx1z9MPVQAAABffQ/uuAAAAQA/INAAAIAVkGgAAkAIyDQAASAGZBgAApIBMAwAAUkCmAQAAKSDTAACAFJBpAABACsg0AAAgBWQaAACQAjINAABIAZkGAACkgEwDAABSQKYBAAApINMAAIAUbJ1pMoP46ng8dl/1zS/OEzMzAACAScg0WZaVZZnVFUWhXw0kD5VpxDJ9McUNSWQaAACwLXmcxs0xRVGYWced2RU/Q1XPMeE5e1dOz8x1jaelmj6fFdmJkM/ExctFVTyfb0oZ5beXVUw55tpfffd2Hw0CAOAYec896Rxj/i9mGmupPM+tKe78gUwj5qGtmtTC2ekmgugkF694Pi8XtXLK6Vl8QNFLnV0JxZpyeqbWAgAAXC0zjW8Exco0YgxqHMXR5YhztsgcjXSqaFe4mGni84deaj4r8smr3tmuZGQaAAB8QtfThMdprAf6VWucxirTN+7ixhexnIGcXVlVTEcKdSJJPy2nZ9koH5/mWbY5rzSfFZu2L2rl6BNYVjnWUuqc1GaUaFGqKfqE1GrBRWktIswDAMBxa7ieJibTVPV848s0vjRTOalIZ6PAIv2Sx2kWpRkX9Imh1ajMcp7n66WkcRoda+xy9Jmm9cXUdqZZzsc/KeyXjLVUVe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2la/O0mNKJXhzBkr65+MdTtD+4N6Jjbvkt8cnHkLnymAQAAqMg0AAAgDf1nmizLwhPFGfRLPh2rEV+CWNVeqgQAAIbTQ6YJBBHz2L9tPvBN3GpdvtICq44MQ2QaAAAOSp/jNOowb/7vm8e3YExeEVdnTRdTjjklPv2EGxtHuNOp/rkgv9QAAKAXvWUaNyUEUoiYMMxXfU/dxcX44q7RN0WsUsyr8ZnGvdOp/itG5p8CAwAAXfR27sl86r4UnznEcsTpvhEXsQK+NfqCV6B6Yk6KiTjinVcBAEAv+hyn8Y126BmsB5WUMKyBELcocUXhzOQ+8FUyXD3fxMhMo+90uiink6JQJ6T0HzV270wr3qMKAACI+j/35JviBhcrvnRfo698c343RfkeVFIAal1n54aamz+xr++xV78zrXuPawAA4HVA4zRiCW6SiJnHXam7rvAMvim+iY2s+9GH70k7XZ+iMu9xDQAAAvYzTmNNFPNBODT4Cg88FtfYS6ZxA5yjdlcw87646j6rUqax73EdLB8AgGO303Eacayl2uY3TVZR+qn1qu+lykgkYsni4mJlumSayrjZ6aSYVfKdaYV7XAMAAJ/d3RtBHBrxvRQYTTGX8oWSxsgSUxnfehtfAgAAu7e7vyMcWNZ8aj4wh0ncdbkVsApxH8dUpjHTxLQLAADsGPewBAAAKSDTAACAFJBpAABACsg0AAAgBWQaAACQAjINAABIAZkGAACkgEwDAABSQKYBAAApINMAAIAUkGkAAEAKyDQAACAFZBoAAJACMg0AAEjB/wFY1yCqkJ38UQAAAABJRU5ErkJggg==" alt="" />
通过这个实例让我们知道,做成一件事,可能一步不行,但多几步一定可以实现!
Redis学习笔记~关于空间换时间的查询案例的更多相关文章
- Redis基础知识之————空间换时间的查询案例
空间与时间 空间换时间是在数据库中经常出现的术语,简单说就是把查询需要的条件进行索引的存储,然后查询时为O(1)的时间复杂度来快速获取数据,从而达到了使用空间存储来换快速的时间响应!对于redis这个 ...
- 【C语言学习笔记】空间换时间,查表法的经典例子!知识就是这么学到的~
我们怎么衡量一个函数/代码块/算法的优劣呢?这需要从多个角度看待.本篇笔记我们先不考虑代码可读性.规范性.可移植性那些角度. 在我们嵌入式中,我们需要根据实际资源的情况来设计我们的代码.比如当我们能用 ...
- Redis学习笔记~目录
回到占占推荐博客索引 百度百科 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合). ...
- Redis学习笔记4-Redis配置详解
在Redis中直接启动redis-server服务时, 采用的是默认的配置文件.采用redis-server xxx.conf 这样的方式可以按照指定的配置文件来运行Redis服务.按照本Redi ...
- Redis学习笔记一:数据结构与对象
1. String(SDS) Redis使用自定义的一种字符串结构SDS来作为字符串的表示. 127.0.0.1:6379> set name liushijie OK 在如上操作中,name( ...
- (转)redis 学习笔记(1)-编译、启动、停止
redis 学习笔记(1)-编译.启动.停止 一.下载.编译 redis是以源码方式发行的,先下载源码,然后在linux下编译 1.1 http://www.redis.io/download 先 ...
- Redis学习笔记二 (BitMap算法分析与BitCount语法)
Redis学习笔记二 一.BitMap是什么 就是通过一个bit位来表示某个元素对应的值或者状态,其中的key就是对应元素本身.我们知道8个bit可以组成一个Byte,所以bitmap本身会极大的节省 ...
- Redis学习笔记4-Redis配置具体解释
在Redis中直接启动redis-server服务时, 採用的是默认的配置文件.採用redis-server xxx.conf 这种方式能够依照指定的配置文件来执行Redis服务. 依照本Redi ...
- redis学习笔记(详细)——高级篇
redis学习笔记(详细)--初级篇 redis学习笔记(详细)--高级篇 redis配置文件介绍 linux环境下配置大于编程 redis 的配置文件位于 Redis 安装目录下,文件名为 redi ...
随机推荐
- 百度地图开发 Android版应用Key申请
一 申请API key 在使用百度地图之前,我们必须去申请一个百度地图的API key,申请地址http://lbsyun.baidu.com/apiconsole/key,自己自行注册一个百度账号, ...
- [转]SQL Server字符串处理函数大全
select语句中只能使用sql函数对字段进行操作(链接sql server), select 字段1 from 表1 where 字段1.IndexOf("云")=1;这条语句不 ...
- Dancing Links & Algorithm X
1 参考链接 http://www.cnblogs.com/steady/archive/2011/03/15/1984791.html#undefined http://en.wikipedia.o ...
- Ubuntu上安装Minecraft服务器
Minecraft由于其独特的魅力吸引了很多玩家.不过游戏的乐趣只有在和朋友一起玩的时候才最有意思,所以很早以前我就想建设自己的服务器.但由于专业知识欠缺,没有实现. 最近接触了Linux服务器,所以 ...
- 原因是出现以下错误: 80040154 没有注册类 (异常来自 HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))
场景: 客户端初始化正常,到IIS服务就报80040154. System.Web.Services.Protocols.SoapException: System.Web.Services.Prot ...
- 【fortify】安全漏洞的分类
https://vulncat.hpefod.com/zh-cn 下面摘要著名的软件安全专家Gary Mc Graw的2006年的新书<Software Security building se ...
- 简单的css js控制table隔行变色
(1)用expression 鼠标滑过变色: <style type="text/css"><!-- table { background-color:#0000 ...
- 如何获取URL中的参数
获取URL中的某个参数或者所有参数以便我们后续去修改这个地址,在程序中是非常必要的.网上有很多这样的代码片段,为了以后查阅方便,顺便整理思路,下面使用2种方法来获取URL中的某个参数. 方法一 ,sp ...
- python基础整理笔记(七)
一. python的类属性与实例属性的注意点 class TestAtt(): aaa = 10 def main(): # case 1 obj1 = TestAtt() obj2 = TestAt ...
- C++函数返回局部指针变量
遇到过好几次关于函数返回指针变量问题,有时候是可以的,有时候是不可以的,然后就混乱了.今天研究了下,结果发现原来和内存分配有关. 用下面的例子分析下吧: char * test() { char a[ ...