Redis源码分析系列二十二: 5 time---"timeCommand"

 代码如下:

void timeCommand(redisClient *c) 
{
struct timeval tv;


/* gettimeofday() can only fail if &tv is a bad address so we
* don't check for errors. */
gettimeofday(&tv,NULL);
addReplyMultiBulkLen(c,2);
addReplyBulkLongLong(c,tv.tv_sec);
addReplyBulkLongLong(c,tv.tv_usec);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

逐一分析。

//自定义检查点: 1 2 3
struct timeval tv;
//定义变量
//自定义检查点: 1 2 3



/* gettimeofday() can only fail if &tv is a bad address so we
* don't check for errors. */
gettimeofday(&tv,NULL);
//获取当前时间
//自定义检查点: 1 2 3

addReplyMultiBulkLen(c,2);
//返回*2\r\n

addReplyBulkLongLong(c,tv.tv_sec);
//返回秒

addReplyBulkLongLong(c,tv.tv_usec);
//返回微秒
//自定义检查点: 1 2 3

具体的格式这里就不分析了,有兴趣自己用wireshark抓包就知道了!

你可能感兴趣的:(redis,redis,qiangzigege,强子哥哥)