Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用hiredis API断开与redis服务器的连接?有 API 可以连接,但我找不到任何关闭连接的函数?是否redisFree会自动执行此操作?
redisFree
redisFree() 确实会关闭连接,并为所有附加对象释放内存。
如有疑问,您可以查看源代码。这很容易理解。
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); }