-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should we use defer close after new a redis client? #1309
Comments
It's always a good idea to explicitly close a resource (like a file handle or network connection) when you know you don't need it anymore, rather than letting the system close it for you when the process ends. That's why you'll see that pattern a lot in Go. In languages other than go, you'll see code that closes things like a Redis client in a handler that the program expects to be called when the program ends. In Go, it's common to use So, given this, no it is not "neccessary" to call it that particular way. But, if you're setting up a client in your app's |
@chenweiyj doesn't @mattwelke answered the question? In my opinion, it would be much easier to navigate through issues if resolved ones are closed. |
I'd consider this solved. @chemidy If you still have questions, you shouldn't re-open this issue. Stack Overflow is a much better platform for asking specific questions related to programming. GitHub issues should be reserved for things you think the library maintainers need to be made aware of. |
how the redis-go close the client automatically? |
Should this be documented? I didn't find it very clear from the current docs ( https://pkg.go.dev/github.com/redis/go-redis/v9#Client.Close):
Nor do I see it in any of the examples. Should that line in the docs be removed? Or maybe reworded? |
It is necessary to call
defer client.Close()
after new a redis client?The text was updated successfully, but these errors were encountered: