Redis源码分析系列十七:processCommand后续

继续研究。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if ((dictSize(c->pubsub_channels) > 0 || listLength(c->pubsub_patterns) > 0)
&&
c->cmd->proc != subscribeCommand &&
c->cmd->proc != unsubscribeCommand &&
c->cmd->proc != psubscribeCommand &&
c->cmd->proc != punsubscribeCommand) 
{
addReplyError(c,"only (P)SUBSCRIBE / (P)UNSUBSCRIBE / QUIT allowed in this context");
return REDIS_OK;
}
在某些状态下,只能使用这几种命令。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
* we are a slave with a broken link with master. */
if (server.masterhost && server.repl_state != REDIS_REPL_CONNECTED &&
server.repl_serve_stale_data == 0 &&
!(c->cmd->flags & REDIS_CMD_STALE))
{
flagTransaction(c);
addReply(c, shared.masterdownerr);
return REDIS_OK;
}
这个当前不执行。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

中间就不说了,直接看看命令执行过程。

~~~~~~~

/* Exec the command */
if (c->flags & REDIS_MULTI &&
c->cmd->proc != execCommand && c->cmd->proc != discardCommand &&
c->cmd->proc != multiCommand && c->cmd->proc != watchCommand)
{
queueMultiCommand(c);
addReply(c,shared.queued);

else 
{
call(c,REDIS_CALL_FULL);

if (listLength(server.ready_keys))
handleClientsBlockedOnLists();

}

假设不是执行事务块命令,则我们需要关注call函数。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

在call函数的上方看到了

/* Call() is the core of Redis execution of a command */
也就是说,call函数是Redis执行一条命令的核心。

我们需要非常严肃认真的对待这个函数,下面开始分析。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/* Sent the command to clients in MONITOR mode, only if the commands are
* not generated from reading an AOF. */
if (listLength(server.monitors) &&
!server.loading &&
!(c->cmd->flags & REDIS_CMD_SKIP_MONITOR))
{
replicationFeedMonitors(c,server.monitors,c->db->id,c->argv,c->argc);

}


这个只有在当前redis为monitor状态才才会执行。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

c->flags &= ~(REDIS_FORCE_AOF|REDIS_FORCE_REPL);

屏蔽掉这两个标识位

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

redisOpArrayInit(&server.also_propagate);

初始化server.also_propagate,这个英文单词还没见过,我查了,繁殖遗传的意思。

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

我个人认为,最重要的语句终于出现了,它就是:

c->cmd->proc(c);!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

等了这么多天,它,终于在江湖上出现了!诚不余欺也。

由于redis有很多命令,我不能每种命令都去执行以下,所以后面将选择若干命令,每个命令一节来讲解。

请听下回分解!

转载于:https://my.oschina.net/qiangzigege/blog/171039

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值