Domanda

How to disconnect to redis server using hiredis API? There is API to connect but I can't find any function to close the connection? Does redisFree will automatically do this ?

È stato utile?

Soluzione

redisFree() will indeed close the connection, and deallocate memory for all attached objects.

When in doubt, you can look at the source code. It is quite easy to understand.

void redisFree(redisContext *c) {
    if (c->fd > 0)
        close(c->fd);
    if (c->obuf != NULL)
        sdsfree(c->obuf);
    if (c->reader != NULL)
        redisReaderFree(c->reader);
    free(c);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top