摘要: hiredis是redis官方提供的c客户端库。在读代码的过程中,发现了一个bug,记录一下。hiredis里定义了一个上下文结构(struct redisContext),代码如下(deps/hiredis/hiredis.h):https://github.com/antirez/hiredis/blob/master/hiredis.h157 /* Context for a connection to Redis */158 typedef struct redisContext {159 int err; /* Error flags, 0 when there is no ...阅读全文
posted @ 2012-06-20 17:47 刘浩de技术博客 阅读(800) | 评论 (0) 编辑
摘要: 纯文本协议,请求-响应模式。看下边链接:http://redis.io/topics/protocol《Unix编程艺术》中明确倡导使用纯文本协议。作者在specification的开头就指出,Redis的协议设计是如下三点的折中:Simple to implementFast to parse by a computerEasy enough to parse by a human一个如此重视性能的代码实现选用了如此简单易懂的协议设计,相信对仍旧执拗于使用二进制协议设计的开发者是个启发。阅读全文
posted @ 2012-05-28 16:35 刘浩de技术博客 阅读(78) | 评论 (0) 编辑
redis源码笔记 - 有关LRU cache相关的代码
摘要: redis可以被作为类似memcached的应用级缓存使用,在内存超过限制时,按照配置的策略,淘汰掉相应的kv,使得内存可以继续留有足够的空间保存新的数据。redis的conf文件中有对该机制的一份很好的解释:194 # Don't use more memory than the specified amount of bytes.195 # When the memory limit is reached Redis will try to remove keys196 # accordingly to the eviction policy selected (see maxme阅读全文
posted @ 2012-05-27 09:15 刘浩de技术博客 阅读(105) | 评论 (0) 编辑
redis源码笔记 - redis对过期值的处理(in redis.c)
摘要: redis允许对key设置超时时间,实现过期key的自动淘汰。这篇blog分析下,其自适应(adaptive)的淘汰机制。redis每隔100ms定时执行的循环(serverCron function)里有如下语句: 655 /* Expire a few keys per cycle, only if this is a master. 656 * On slaves we wait for DEL operations synthesized by the master 657 * in order to guarantee a strict consisten...阅读全文
posted @ 2012-05-25 15:56 刘浩de技术博客 阅读(110) | 评论 (0) 编辑
摘要: 作者在bio.c的头注释中对设计进行了详细的介绍/* Background I/O service for Redis. 这个文件是redis后台IO服务的实现 * * This file implements operations that we need to perform in the background. * Currently there is only a single operation, that is a background close(2) * system call. This is needed as when the process is the last ..阅读全文
posted @ 2012-05-17 20:52 刘浩de技术博客 阅读(75) | 评论 (0) 编辑
摘要: adlist是redis自己是实现的一个通用的双向链表。------------------------------------------------adlist.h---------------------------------------------------#ifndef __ADLIST_H__#define __ADLIST_H__/* Node, List, and Iterator are the only data structures used currently. */typedef struct listNode {struct listNode *prev;str阅读全文
posted @ 2012-05-10 23:24 刘浩de技术博客 阅读(77) | 评论 (0) 编辑
redis源码笔记-redis.conf
摘要: redis.conf是redis-server的配置文件# Redis configuration file example# Note on units: when memory size is needed, it is possible to specifiy# it in the usual form of 1k 5GB 4M and so forth:## 1k => 1000 bytes# 1kb => 1024 bytes# 1m => 1000000 bytes# 1mb => 1024*1024 bytes# 1g => 1000000000 b阅读全文
posted @ 2012-05-10 00:10 刘浩de技术博客 阅读(79) | 评论 (0) 编辑