diff --git a/src/multi.c b/src/multi.c index 1504bb09b7ecca52b6c6df5fb45eac2891b15cf5..65ec38a8d0e34b8a1c908d7056f9281314e5258e 100644 --- a/src/multi.c +++ b/src/multi.c @@ -112,7 +112,7 @@ void execCommand(redisClient *c) { c->argc = c->mstate.commands[j].argc; c->argv = c->mstate.commands[j].argv; c->cmd = c->mstate.commands[j].cmd; - call(c); + call(c,REDIS_CALL_FULL); /* Commands may alter argc/argv, restore mstate. */ c->mstate.commands[j].argc = c->argc; diff --git a/src/redis.c b/src/redis.c index 9f5aa4dbf62c199ff58f17281ca295ec2810bb9f..765f58dad3f98081cd323c29c76178f448904d02 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1171,24 +1171,34 @@ struct redisCommand *lookupCommandByCString(char *s) { } /* Call() is the core of Redis execution of a command */ -void call(redisClient *c) { +void call(redisClient *c, int flags) { long long dirty, start = ustime(), duration; dirty = server.dirty; c->cmd->proc(c); dirty = server.dirty-dirty; duration = ustime()-start; - c->cmd->microseconds += duration; - slowlogPushEntryIfNeeded(c->argv,c->argc,duration); - c->cmd->calls++; - - if (server.aof_state != REDIS_AOF_OFF && dirty > 0) - feedAppendOnlyFile(c->cmd,c->db->id,c->argv,c->argc); - if ((dirty > 0 || c->cmd->flags & REDIS_CMD_FORCE_REPLICATION) && - listLength(server.slaves)) - replicationFeedSlaves(server.slaves,c->db->id,c->argv,c->argc); - if (listLength(server.monitors)) - replicationFeedMonitors(server.monitors,c->db->id,c->argv,c->argc); + + /* When EVAL is called loading the AOF we don't want commands called + * from Lua to go into the slowlog or to populate statistics. */ + if (server.loading && c->flags & REDIS_LUA_CLIENT) + flags &= ~(REDIS_CALL_SLOWLOG | REDIS_CALL_STATS); + + if (flags & REDIS_CALL_SLOWLOG) + slowlogPushEntryIfNeeded(c->argv,c->argc,duration); + if (flags & REDIS_CALL_STATS) { + c->cmd->microseconds += duration; + c->cmd->calls++; + } + if (flags & REDIS_CALL_PROPAGATE) { + if (server.aof_state != REDIS_AOF_OFF && dirty > 0) + feedAppendOnlyFile(c->cmd,c->db->id,c->argv,c->argc); + if ((dirty > 0 || c->cmd->flags & REDIS_CMD_FORCE_REPLICATION) && + listLength(server.slaves)) + replicationFeedSlaves(server.slaves,c->db->id,c->argv,c->argc); + if (listLength(server.monitors)) + replicationFeedMonitors(server.monitors,c->db->id,c->argv,c->argc); + } server.stat_numcommands++; } @@ -1317,7 +1327,7 @@ int processCommand(redisClient *c) { queueMultiCommand(c); addReply(c,shared.queued); } else { - call(c); + call(c,REDIS_CALL_FULL); } return REDIS_OK; } diff --git a/src/redis.h b/src/redis.h index 66a51c835f80ef0b82a98e5ec4e66f55036ec928..8f19ad37f993c7829e78bbf1fcbce4aa94bd06f8 100644 --- a/src/redis.h +++ b/src/redis.h @@ -237,6 +237,13 @@ points are configured. */ #define REDIS_SHUTDOWN_NOSAVE 2 /* Don't SAVE on SHUTDOWN. */ +/* Command call flags, see call() function */ +#define REDIS_CALL_NONE 0 +#define REDIS_CALL_SLOWLOG 1 +#define REDIS_CALL_STATS 2 +#define REDIS_CALL_PROPAGATE 4 +#define REDIS_CALL_FULL (REDIS_CALL_SLOWLOG | REDIS_CALL_STATS | REDIS_CALL_PROPAGATE) + /* We can print the stacktrace, so our assert is defined this way: */ #define redisAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_redisAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1))) #define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1))) @@ -938,7 +945,7 @@ int processCommand(redisClient *c); void setupSignalHandlers(void); struct redisCommand *lookupCommand(sds name); struct redisCommand *lookupCommandByCString(char *s); -void call(redisClient *c); +void call(redisClient *c, int flags); int prepareForShutdown(); void redisLog(int level, const char *fmt, ...); void redisLogRaw(int level, const char *msg); diff --git a/src/scripting.c b/src/scripting.c index 2eac840c52e5707829a57f5deab6950d9bf086cc..75788a3a5e25b50dd35ffc82187a85115108b484 100644 --- a/src/scripting.c +++ b/src/scripting.c @@ -221,7 +221,8 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) { if (cmd->flags & REDIS_CMD_WRITE) server.lua_write_dirty = 1; /* Run the command */ - cmd->proc(c); + c->cmd = cmd; + call(c,REDIS_CALL_SLOWLOG | REDIS_CALL_STATS); /* Convert the result of the Redis command into a suitable Lua type. * The first thing we need is to create a single string from the client