Commit 7156f43c authored by antirez's avatar antirez
Browse files

Correctly glue the reply buffer. For now returned as it is to Lua, but will be...

Correctly glue the reply buffer. For now returned as it is to Lua, but will be converted into Lua native type later.
parent 0f1d64ca
...@@ -65,6 +65,7 @@ redisClient *createClient(int fd) { ...@@ -65,6 +65,7 @@ redisClient *createClient(int fd) {
/* Set the event loop to listen for write events on the client's socket. /* Set the event loop to listen for write events on the client's socket.
* Typically gets called every time a reply is built. */ * Typically gets called every time a reply is built. */
int _installWriteEvent(redisClient *c) { int _installWriteEvent(redisClient *c) {
if (c->flags & REDIS_LUA_CLIENT) return REDIS_OK;
if (c->fd <= 0) return REDIS_ERR; if (c->fd <= 0) return REDIS_ERR;
if (c->bufpos == 0 && listLength(c->reply) == 0 && if (c->bufpos == 0 && listLength(c->reply) == 0 &&
(c->replstate == REDIS_REPL_NONE || (c->replstate == REDIS_REPL_NONE ||
......
...@@ -148,6 +148,7 @@ ...@@ -148,6 +148,7 @@
#define REDIS_CLOSE_AFTER_REPLY 128 /* Close after writing entire reply. */ #define REDIS_CLOSE_AFTER_REPLY 128 /* Close after writing entire reply. */
#define REDIS_UNBLOCKED 256 /* This client was unblocked and is stored in #define REDIS_UNBLOCKED 256 /* This client was unblocked and is stored in
server.unblocked_clients */ server.unblocked_clients */
#define REDIS_LUA_CLIENT 512 /* This is a non connected client used by Lua */
/* Client request types */ /* Client request types */
#define REDIS_REQ_INLINE 1 #define REDIS_REQ_INLINE 1
......
...@@ -14,7 +14,7 @@ int luaRedisCommand(lua_State *lua) { ...@@ -14,7 +14,7 @@ int luaRedisCommand(lua_State *lua) {
argv = zmalloc(sizeof(robj*)*argc); argv = zmalloc(sizeof(robj*)*argc);
for (j = 0; j < argc; j++) 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 */ /* Command lookup */
cmd = lookupCommand(argv[0]->ptr); cmd = lookupCommand(argv[0]->ptr);
...@@ -34,7 +34,7 @@ int luaRedisCommand(lua_State *lua) { ...@@ -34,7 +34,7 @@ int luaRedisCommand(lua_State *lua) {
* output buffers. */ * output buffers. */
reply = sdsempty(); reply = sdsempty();
if (c->bufpos) { if (c->bufpos) {
reply = sdscatlen(reply,c->bufpos,c->buf); reply = sdscatlen(reply,c->buf,c->bufpos);
c->bufpos = 0; c->bufpos = 0;
} }
while(listLength(c->reply)) { while(listLength(c->reply)) {
...@@ -43,7 +43,8 @@ int luaRedisCommand(lua_State *lua) { ...@@ -43,7 +43,8 @@ int luaRedisCommand(lua_State *lua) {
sdscatlen(reply,o->ptr,sdslen(o->ptr)); sdscatlen(reply,o->ptr,sdslen(o->ptr));
listDelNode(c->reply,listFirst(c->reply)); 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 /* Clean up. Command code may have changed argv/argc so we use the
* argv/argc of the client instead of the local variables. */ * argv/argc of the client instead of the local variables. */
...@@ -65,6 +66,7 @@ void scriptingInit(void) { ...@@ -65,6 +66,7 @@ void scriptingInit(void) {
/* Create the (non connected) client that we use to execute Redis commands /* Create the (non connected) client that we use to execute Redis commands
* inside the Lua interpreter */ * inside the Lua interpreter */
server.lua_client = createClient(-1); server.lua_client = createClient(-1);
server.lua_client->flags |= REDIS_LUA_CLIENT;
server.lua = lua; server.lua = lua;
} }
...@@ -134,8 +136,10 @@ void evalCommand(redisClient *c) { ...@@ -134,8 +136,10 @@ void evalCommand(redisClient *c) {
addReplyErrorFormat(c,"Error compiling script (new function): %s\n", addReplyErrorFormat(c,"Error compiling script (new function): %s\n",
lua_tostring(lua,-1)); lua_tostring(lua,-1));
lua_pop(lua,1); lua_pop(lua,1);
sdsfree(funcdef);
return; return;
} }
sdsfree(funcdef);
if (lua_pcall(lua,0,0,0)) { if (lua_pcall(lua,0,0,0)) {
addReplyErrorFormat(c,"Error running script (new function): %s\n", addReplyErrorFormat(c,"Error running script (new function): %s\n",
lua_tostring(lua,-1)); lua_tostring(lua,-1));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment