Skip to content

Commit ce8b772

Browse files
committed
Now Lua scripts dispatch Redis commands properly calling the call() function. In order to make this possible call() was improved with a new flags argument that controls how the Redis command is executed.
1 parent d876678 commit ce8b772

File tree

4 files changed

+34
-16
lines changed

4 files changed

+34
-16
lines changed

src/multi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ void execCommand(redisClient *c) {
112112
c->argc = c->mstate.commands[j].argc;
113113
c->argv = c->mstate.commands[j].argv;
114114
c->cmd = c->mstate.commands[j].cmd;
115-
call(c);
115+
call(c,REDIS_CALL_FULL);
116116

117117
/* Commands may alter argc/argv, restore mstate. */
118118
c->mstate.commands[j].argc = c->argc;

src/redis.c

+23-13
Original file line numberDiff line numberDiff line change
@@ -1171,24 +1171,34 @@ struct redisCommand *lookupCommandByCString(char *s) {
11711171
}
11721172

11731173
/* Call() is the core of Redis execution of a command */
1174-
void call(redisClient *c) {
1174+
void call(redisClient *c, int flags) {
11751175
long long dirty, start = ustime(), duration;
11761176

11771177
dirty = server.dirty;
11781178
c->cmd->proc(c);
11791179
dirty = server.dirty-dirty;
11801180
duration = ustime()-start;
1181-
c->cmd->microseconds += duration;
1182-
slowlogPushEntryIfNeeded(c->argv,c->argc,duration);
1183-
c->cmd->calls++;
1184-
1185-
if (server.aof_state != REDIS_AOF_OFF && dirty > 0)
1186-
feedAppendOnlyFile(c->cmd,c->db->id,c->argv,c->argc);
1187-
if ((dirty > 0 || c->cmd->flags & REDIS_CMD_FORCE_REPLICATION) &&
1188-
listLength(server.slaves))
1189-
replicationFeedSlaves(server.slaves,c->db->id,c->argv,c->argc);
1190-
if (listLength(server.monitors))
1191-
replicationFeedMonitors(server.monitors,c->db->id,c->argv,c->argc);
1181+
1182+
/* When EVAL is called loading the AOF we don't want commands called
1183+
* from Lua to go into the slowlog or to populate statistics. */
1184+
if (server.loading && c->flags & REDIS_LUA_CLIENT)
1185+
flags &= ~(REDIS_CALL_SLOWLOG | REDIS_CALL_STATS);
1186+
1187+
if (flags & REDIS_CALL_SLOWLOG)
1188+
slowlogPushEntryIfNeeded(c->argv,c->argc,duration);
1189+
if (flags & REDIS_CALL_STATS) {
1190+
c->cmd->microseconds += duration;
1191+
c->cmd->calls++;
1192+
}
1193+
if (flags & REDIS_CALL_PROPAGATE) {
1194+
if (server.aof_state != REDIS_AOF_OFF && dirty > 0)
1195+
feedAppendOnlyFile(c->cmd,c->db->id,c->argv,c->argc);
1196+
if ((dirty > 0 || c->cmd->flags & REDIS_CMD_FORCE_REPLICATION) &&
1197+
listLength(server.slaves))
1198+
replicationFeedSlaves(server.slaves,c->db->id,c->argv,c->argc);
1199+
if (listLength(server.monitors))
1200+
replicationFeedMonitors(server.monitors,c->db->id,c->argv,c->argc);
1201+
}
11921202
server.stat_numcommands++;
11931203
}
11941204

@@ -1317,7 +1327,7 @@ int processCommand(redisClient *c) {
13171327
queueMultiCommand(c);
13181328
addReply(c,shared.queued);
13191329
} else {
1320-
call(c);
1330+
call(c,REDIS_CALL_FULL);
13211331
}
13221332
return REDIS_OK;
13231333
}

src/redis.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@
237237
points are configured. */
238238
#define REDIS_SHUTDOWN_NOSAVE 2 /* Don't SAVE on SHUTDOWN. */
239239

240+
/* Command call flags, see call() function */
241+
#define REDIS_CALL_NONE 0
242+
#define REDIS_CALL_SLOWLOG 1
243+
#define REDIS_CALL_STATS 2
244+
#define REDIS_CALL_PROPAGATE 4
245+
#define REDIS_CALL_FULL (REDIS_CALL_SLOWLOG | REDIS_CALL_STATS | REDIS_CALL_PROPAGATE)
246+
240247
/* We can print the stacktrace, so our assert is defined this way: */
241248
#define redisAssertWithInfo(_c,_o,_e) ((_e)?(void)0 : (_redisAssertWithInfo(_c,_o,#_e,__FILE__,__LINE__),_exit(1)))
242249
#define redisAssert(_e) ((_e)?(void)0 : (_redisAssert(#_e,__FILE__,__LINE__),_exit(1)))
@@ -938,7 +945,7 @@ int processCommand(redisClient *c);
938945
void setupSignalHandlers(void);
939946
struct redisCommand *lookupCommand(sds name);
940947
struct redisCommand *lookupCommandByCString(char *s);
941-
void call(redisClient *c);
948+
void call(redisClient *c, int flags);
942949
int prepareForShutdown();
943950
void redisLog(int level, const char *fmt, ...);
944951
void redisLogRaw(int level, const char *msg);

src/scripting.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
221221
if (cmd->flags & REDIS_CMD_WRITE) server.lua_write_dirty = 1;
222222

223223
/* Run the command */
224-
cmd->proc(c);
224+
c->cmd = cmd;
225+
call(c,REDIS_CALL_SLOWLOG | REDIS_CALL_STATS);
225226

226227
/* Convert the result of the Redis command into a suitable Lua type.
227228
* The first thing we need is to create a single string from the client

0 commit comments

Comments
 (0)