X-Git-Url: https://git.saurik.com/redis.git/blobdiff_plain/df541beae372f40e9ce82a0780171e7d7a8e67de..0f1d64ca577c8594e26b9e1663e49c8e1bc13757:/src/networking.c diff --git a/src/networking.c b/src/networking.c index 4a6a8afd..b26c2059 100644 --- a/src/networking.c +++ b/src/networking.c @@ -14,14 +14,20 @@ redisClient *createClient(int fd) { redisClient *c = zmalloc(sizeof(redisClient)); c->bufpos = 0; - anetNonBlock(NULL,fd); - anetTcpNoDelay(NULL,fd); - if (aeCreateFileEvent(server.el,fd,AE_READABLE, - readQueryFromClient, c) == AE_ERR) - { - close(fd); - zfree(c); - return NULL; + /* passing -1 as fd it is possible to create a non connected client. + * This is useful since all the Redis commands needs to be executed + * in the context of a client. When commands are executed in other + * contexts (for instance a Lua script) we need a non connected client. */ + if (fd != -1) { + anetNonBlock(NULL,fd); + anetTcpNoDelay(NULL,fd); + if (aeCreateFileEvent(server.el,fd,AE_READABLE, + readQueryFromClient, c) == AE_ERR) + { + close(fd); + zfree(c); + return NULL; + } } selectDb(c,0);