سؤال

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