Question

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 ?

Était-ce utile?

La solution

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);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top