7月 212013
 

 

1. redis的lru的使用

其中:

这个赋值是怎么体现lru的工作机制的?

 

2. 按照下面的调用过程来看redis对每个命令的处理过程:

至于redis协议中的每条指定对应server端的那一个函数,不会看到一个if..else.. 或者 switch结构的, 从 redisCommandTable 中来找就足够了(当然,quit命令找不到,似乎也只有quit命令)

 

3. 今天还了解一下细节

1) key和value都是作为redis的object来存储的,相同的value是重复使用的

2) 过期机制是通过将要过期的key写到一个过期table中来做的,这个是和memcache不同的

4. redis是支持认证机制的,当然,这样会多一次请求,而且认证请求不能和其它请求一起打包执行的

 

5. 关于Redis的LRU:

Redis的LRU是不精确的,不是在allkey中LRU的,而是在allkey中随机选取 maxmemory-samples 来LRU的,这一点要考虑一下是否满足需求。

redis_lru

 

(了解一下概率的计算方法吧)

摘录: http://oldblog.antirez.com/post/redis-as-LRU-cache.html

maxmemory-samples number_of_samples

The last config option is used to tune the algorithms precision. In order to save memory Redis just adds a 22 bits field to every object for LRU. When we need to remove a key we sample N keys, and remove the one that was idle for longer time. For default three keys are sampled, that is a reasonable approximation of LRU in the long run, but you can get more precision at the cost of some more CPU time changing the number of keys to sample.

Redis 2.2 的配置文件关于LRU的相关说明:

 

 Posted by at 上午 12:45

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据