+ lua_gc(lua,LUA_GCSTEP,1);
+
+ /* If we have slaves attached we want to replicate this command as
+ * EVAL instead of EVALSHA. We do this also in the AOF as currently there
+ * is no easy way to propagate a command in a different way in the AOF
+ * and in the replication link.
+ *
+ * IMPROVEMENT POSSIBLE:
+ * 1) Replicate this command as EVALSHA in the AOF.
+ * 2) Remember what slave already received a given script, and replicate
+ * the EVALSHA against this slaves when possible.
+ */
+ if (evalsha) {
+ robj *script = dictFetchValue(server.lua_scripts,c->argv[1]->ptr);
+
+ redisAssert(script != NULL);
+ rewriteClientCommandArgument(c,0,
+ resetRefCount(createStringObject("EVAL",4)));
+ rewriteClientCommandArgument(c,1,script);
+ }
+}
+
+void evalCommand(redisClient *c) {
+ evalGenericCommand(c,0);
+}
+
+void evalShaCommand(redisClient *c) {
+ if (sdslen(c->argv[1]->ptr) != 40) {
+ /* We know that a match is not possible if the provided SHA is
+ * not the right length. So we return an error ASAP, this way
+ * evalGenericCommand() can be implemented without string length
+ * sanity check */
+ addReply(c, shared.noscripterr);
+ return;
+ }
+ evalGenericCommand(c,1);