summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2012-02-02 16:30:52 +0100
committerantirez <antirez@gmail.com>2012-02-02 16:30:52 +0100
commitce8b772be7dcd0dec767c7bdfa3b8702806d69c4 (patch)
tree0eaa595f8e0956746e18da269a9c95b7dc3b6365 /src
parentd876678b5eb0db0df66a658faeb8fb71e236a634 (diff)
downloadredis-ce8b772be7dcd0dec767c7bdfa3b8702806d69c4.tar.gz
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.
Diffstat (limited to 'src')
-rw-r--r--src/multi.c2
-rw-r--r--src/redis.c36
-rw-r--r--src/redis.h9
-rw-r--r--src/scripting.c3
4 files changed, 34 insertions, 16 deletions
diff --git a/src/multi.c b/src/multi.c
index 1504bb09b..65ec38a8d 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 9f5aa4dbf..765f58dad 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 66a51c835..8f19ad37f 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 2eac840c5..75788a3a5 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