------------7月3日------------

  1. /* The redisOp structure defines a Redis Operation, that is an instance of
  2. * a command with an argument vector, database ID, propagation target
  3. * (REDIS_PROPAGATE_*), and command pointer.
  4. *
  5. * Currently only used to additionally propagate more commands to AOF/Replication
  6. * after the propagation of the executed command. */
  7. typedef struct redisOp {
  8. robj **argv;
  9. int argc, dbid, target;
  10. struct redisCommand *cmd;
  11. } redisOp;

argc 参数个数,argv参数数组,跟main函数里的参数一样

dbid,数据库id,target(propagation传播),暂时不懂。

cmd操作命令。

------------7月4日--------------------

  1. struct redisCommand {
  2. char *name;
  3. redisCommandProc *proc;
  4. int arity;
  5. char *sflags; /* Flags as string representation, one char per flag. */
  6. int flags; /* The actual flags, obtained from the 'sflags' field. */
  7. /* Use a function to determine keys arguments in a command line.
  8. * Used for Redis Cluster redirect. */
  9. redisGetKeysProc *getkeys_proc;
  10. /* What keys should be loaded in background when calling this command? */
  11. int firstkey; /* The first argument that's a key (0 = no keys) */
  12. int lastkey; /* The last argument that's a key */
  13. int keystep; /* The step between first and last key */
  14. long long microseconds, calls;
  15. };

给两三个例子就能懂一点,自己看代码

  1. void getCommand(redisClient *c);
  2. void lsetCommand(redisClient *c);
  3. void saddCommand(redisClient *c);
  4.  
  5. {"get",getCommand,,"r",,NULL,,,,,},
  6. {"lset",lsetCommand,,"wm",,NULL,,,,,},
  7. {"sadd",saddCommand,-,"wm",,NULL,,,,,}
  8.  
  9. /* Our command table.
  10. *
  11. * Every entry is composed of the following fields:
  12. *
  13. * name: a string representing the command name.
  14. * function: pointer to the C function implementing the command.
  15. * arity: number of arguments, it is possible to use -N to say >= N
  16. * sflags: command flags as string. See below for a table of flags.
  17. * flags: flags as bitmask. Computed by Redis using the 'sflags' field.
  18. * get_keys_proc: an optional function to get key arguments from a command.
  19. * This is only used when the following three fields are not
  20. * enough to specify what arguments are keys.
  21. * first_key_index: first argument that is a key
  22. * last_key_index: last argument that is a key
  23. * key_step: step to get all the keys from first to last argument. For instance
  24. * in MSET the step is two since arguments are key,val,key,val,...
  25. * microseconds: microseconds of total execution time for this command.
  26. * calls: total number of calls of this command.
  27. *
  28. * The flags, microseconds and calls fields are computed by Redis and should
  29. * always be set to zero.
  30. *
  31. * Command flags are expressed using strings where every character represents
  32. * a flag. Later the populateCommandTable() function will take care of
  33. * populating the real 'flags' field using this characters.
  34. *
  35. * This is the meaning of the flags:
  36. *
  37. * w: write command (may modify the key space).
  38. * r: read command (will never modify the key space).
  39. * m: may increase memory usage once called. Don't allow if out of memory.
  40. * a: admin command, like SAVE or SHUTDOWN.
  41. * p: Pub/Sub related command.
  42. * f: force replication of this command, regardless of server.dirty.
  43. * s: command not allowed in scripts.
  44. * R: random command. Command is not deterministic, that is, the same command
  45. * with the same arguments, with the same key space, may have different
  46. * results. For instance SPOP and RANDOMKEY are two random commands.
  47. * S: Sort command output array if called from script, so that the output
  48. * is deterministic.
  49. * l: Allow command while loading the database.
  50. * t: Allow command while a slave has stale data but is not allowed to
  51. * server this data. Normally no command is accepted in this condition
  52. * but just a few.
  53. * M: Do not automatically propagate the command on MONITOR.
  54. * k: Perform an implicit ASKING for this command, so the command will be
  55. * accepted in cluster mode if the slot is marked as 'importing'.
  56. */

很明显,redisCommandProc是个函数指针,

  1. typedef void redisCommandProc(redisClient *c);

--------------7月5日----------------------

还是说上面的命令吧

  1. {"get",getCommand,2,"r",0,NULL,1,1,1,0,0},
  2.  
  3. 命令名字叫get,具体实现在getCommand里面,参数有两个(包括get?get name),模式为只读(will never modify the key space)。 
  1. {"lset",lsetCommand,4,"wm",0,NULL,1,1,1,0,0},
    命令名字叫lset,具体实现在lsetCommand函数,参数有4个(lset mylist 3 juan”),模式为写,会使用内存(may increase memory usage once called. Don't allow if out of memory)。

-----------------7月10日----------------------
redisServer里有个aeEventLoop,牵涉到Redis的事件。
Redis事件分两种:

  1. 处理文件事件:在多个客户端中实现多路复用,接受它们发来的命令请求,并将命令的执行结果返回给客户端。

  2. 时间事件:实现服务器常规操作。

  1. /* Types and data structures */
  2. typedef void aeFileProc(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask);
  3. typedef int aeTimeProc(struct aeEventLoop *eventLoop, long long id, void *clientData);
  4. typedef void aeEventFinalizerProc(struct aeEventLoop *eventLoop, void *clientData);
  5.  
  6. /* File event structure */
  7. typedef struct aeFileEvent {
  8. int mask; /* one of AE_(READABLE|WRITABLE) */
  9. aeFileProc *rfileProc;
  10. aeFileProc *wfileProc;
  11. void *clientData;
  12. } aeFileEvent;
  13.  
  14. /* Time event structure */
  15. typedef struct aeTimeEvent {
  16. long long id; /* time event identifier. */
  17. long when_sec; /* seconds */
  18. long when_ms; /* milliseconds */
  19. aeTimeProc *timeProc;
  20. aeEventFinalizerProc *finalizerProc;
  21. void *clientData;
  22. struct aeTimeEvent *next;
  23. } aeTimeEvent;

Redis源码研究--redis.h的更多相关文章

  1. Redis源码研究--字典

    计划每天花1小时学习Redis 源码.在博客上做个记录. --------6月18日----------- redis的字典dict主要涉及几个数据结构, dictEntry:具体的k-v链表结点 d ...

  2. Redis源码研究--启动过程

    ---------------------6月23日--------------------------- Redis启动入口即main函数在redis.c文件,伪代码如下: int main(int ...

  3. Redis源码研究—基础知识

    1. Redis 是什么 Redis是一个开源的使用ANSI C语言编写的基于内存的key/value存储系统,与memcache类似,但它支持的value类型更多,包括:字符串(string).链表 ...

  4. Redis源码研究--字符串

    之前看的内容,占个位子,以后补上. ------------8月2日------------- 好久没看了,惭愧,今天抽了点时间重新看了Redis的字符串,一边写博客,一边看. Redis的字符串主要 ...

  5. Redis源码研究:哈希表 - 蕫的博客

    [http://dongxicheng.org/nosql/redis-code-hashtable/] 1. Redis中的哈希表 前面提到Redis是个key/value存储系统,学过数据结构的人 ...

  6. Redis源码研究--跳表

    -------------6月29日-------------------- 简单看了下跳表这一数据结构,理解起来很真实,效率可以和红黑树相比.我就喜欢这样的. typedef struct zski ...

  7. Redis源码研究--双向链表

    之前看的内容,占个位子,以后补上. ----------8月4日--------------- 双向链表这部分看的比较爽,代码写的中规中矩,心里窃喜,跟之前学的<数据结构>这本书中差不多. ...

  8. Redis源码剖析--源码结构解析

    请持续关注我的个人博客:https://zcheng.ren 找工作那会儿,看了黄建宏老师的<Redis设计与实现>,对redis的部分实现有了一个简明的认识.在面试过程中,redis确实 ...

  9. 玩一把redis源码(一):为redis添加自己的列表类型

    2019年第一篇文档,为2019年做个良好的开端,本文档通过step by step的方式向读者展示如何为redis添加一个数据类型,阅读本文档后读者对redis源码的执行逻辑会有比较清晰的认识,并且 ...

随机推荐

  1. EF——使用Data Annotations和Fluent API配置数据库的映射配置 02.01(转)

    要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...

  2. 【手把手教你Elmah】如何在MVC.NET项目中在线查看【错误日志】

     一.  在NuGet下载Elmah.MVC dll文件!  或者点击下载dll文件,并且引用客户端. 二.配置WebConfig <sectionGroup name="elmah& ...

  3. IOS 沙盒机制 && 关于document\library\tmp的灵活使用

    默认情况下,每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件Documents:苹果建议将程序中建立的或在程序中浏览到的文件数 ...

  4. org-reveal

    环境: Debian 8 Emacs 24.4 org-reveal是在emacs org-mode中使用reveal.js的一个插件. emacs 24.4自带的org版本是8.2.10,这个版本似 ...

  5. 100天成就卓越领导力:新晋领导者的First100训练法

    <100天成就卓越领导力:新晋领导者的First100训练法> 基本信息 原书名:Your Frist 100 days: How to Make Maximum Impact in Yo ...

  6. tornado 杂记

    一.建立一个简单的 hello world 网页 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import tornado.iolo ...

  7. MacOS显示和不显示隐藏文件

    defaults write com.apple.finder AppleShowAllFiles Yes && killall Finder //显示隐藏文件 defaults wr ...

  8. android百度地图中的地图缩放级别

    前期搭建百度地图的环境就不说了,网上一搜一大把,这里只讲地图的缩放,大神可以直接绕道 首先在类的内部初始化一个百度地图的对象 private BaiduMap mBaiduMap; 然后在OnCrea ...

  9. 【转】用java实例学习MVC模式

    .1 MVC模式 MVC是三个单词的缩写,这三个单词分别为:模型(Model).视图(View)和控制(Controller).MVC模式的目的就是实现Web系统的职能分工.下面以J2EE开发进行介绍 ...

  10. 二维码zxing源码分析(四)wifi部分

    前三个部分的地址是:ZXING源码分析(一)CAMERA部分  . zxing源码分析(二)decode部分.zxing源码分析(三)result.history部分 前面三篇文章基本上已经把zxin ...