和mongo的slowlog一样,redis中对于操作时间较长(默认为10秒)的命令也会记录下来,不过它将它们保存在redisServer结构中的slowlog这个链表中,新进来的log排在链表头部,这个链表的长度可以配置,超过长度(默认为128)则将链表尾部元素踢掉。
链表中的元素是slowlogEntry:
    // This structure defines an entry inside the slow log list.
    
     typedef struct slowlogEntry {
    
       robj** argv;
    
       int argc;
    
       long long id;  // Unique entry identifier.
    
       long long duration;  // Time spent by the query, in nanoseconds.
    
       time_t time;  // Unix time at which the query was executed.
    
     } slowlogEntry;
    
    
  
argv最多只保存32个,如果多出来了,则第32个改为"... (%d more arguments)",如果参数是字符串并且长度超过128,则将其替换为"... (%lu more bytes)",argv共享的是client中的argv,所以push entry时会增加原有argv的引用计数。
j接口如下:
    // Exported API.
    
     void slowlogInit(void);
    
     void slowlogPushEntryIfNeeded(robj** argv, int argc, long long duration);
    
    
    
     // Exported commands.
    
     void slowlogCommand(redisClient* c); 
    
  
    
  
slowlogCommand是执行slowlog命令,命令带的参数在redisClient中的argv中。看起来,它支持reset,len,get三个子命令。reset,len不用说,get n代表获取最新的n条slowlog记录。

