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 ?

有帮助吗?

解决方案

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);
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top