/* Set the event loop to listen for write events on the client's socket.
* Typically gets called every time a reply is built. */
int _installWriteEvent(redisClient *c) {
+ if (c->flags & REDIS_LUA_CLIENT) return REDIS_OK;
if (c->fd <= 0) return REDIS_ERR;
if (c->bufpos == 0 && listLength(c->reply) == 0 &&
(c->replstate == REDIS_REPL_NONE ||
#define REDIS_CLOSE_AFTER_REPLY 128 /* Close after writing entire reply. */
#define REDIS_UNBLOCKED 256 /* This client was unblocked and is stored in
server.unblocked_clients */
+#define REDIS_LUA_CLIENT 512 /* This is a non connected client used by Lua */
/* Client request types */
#define REDIS_REQ_INLINE 1
argv = zmalloc(sizeof(robj*)*argc);
for (j = 0; j < argc; j++)
- argv[j] = createStringObject(lua_tostring(lua,j+1),lua_strlen(lua,j+1));
+ argv[j] = createStringObject((char*)lua_tostring(lua,j+1),lua_strlen(lua,j+1));
/* Command lookup */
cmd = lookupCommand(argv[0]->ptr);
* output buffers. */
reply = sdsempty();
if (c->bufpos) {
- reply = sdscatlen(reply,c->bufpos,c->buf);
+ reply = sdscatlen(reply,c->buf,c->bufpos);
c->bufpos = 0;
}
while(listLength(c->reply)) {
sdscatlen(reply,o->ptr,sdslen(o->ptr));
listDelNode(c->reply,listFirst(c->reply));
}
- lua_pushnumber(lua,1);
+ lua_pushlstring(lua,reply,sdslen(reply));
+ sdsfree(reply);
/* Clean up. Command code may have changed argv/argc so we use the
* argv/argc of the client instead of the local variables. */
/* Create the (non connected) client that we use to execute Redis commands
* inside the Lua interpreter */
server.lua_client = createClient(-1);
+ server.lua_client->flags |= REDIS_LUA_CLIENT;
server.lua = lua;
}
addReplyErrorFormat(c,"Error compiling script (new function): %s\n",
lua_tostring(lua,-1));
lua_pop(lua,1);
+ sdsfree(funcdef);
return;
}
+ sdsfree(funcdef);
if (lua_pcall(lua,0,0,0)) {
addReplyErrorFormat(c,"Error running script (new function): %s\n",
lua_tostring(lua,-1));