When should kv.close()
be called?
#27467
Replies: 3 comments
-
Did you ever find a conclusive answer to this? I've been digging through the documentation but without luck so far. |
Beta Was this translation helpful? Give feedback.
-
I didn't find anything special about FoundationDB (which KV is built on) with regard to managing connections, so I think the same best practices for managing other database connections applies here. In general, you should leave a connection open for as long as you're using it, and should close it to ensure ongoing transactions get resolved, and any resources held open for the connection are cleaned up. How important this is depends on the application. If you're just writing a small script or a program that doesn't use concurrency, the resources a connection uses won't be high enough that you would notice a difference if you're closing it properly or not. If your script app happens to exit while a transaction is ongoing that could cause an error. In an application like a server, that's dealing with a lot of concurrent requests, or something that's using web workers, it becomes more important to manage your connections. You want to leave them open because they're being used constantly, but you need to make sure they're closed gracefully if your application is shut down or crashes. I don't think Deno KV has connection pooling built in, so you'd probably want to use a third party module to create and manage a connection pool in a production application. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
FYI, you can use
https://github.com/denoland/deno/blob/v2.2.6/ext/kv/01_db.ts#L422-L424 |
Beta Was this translation helpful? Give feedback.
-
I've been digging into using Deno KV, and I was wondering how others are approaching interacting with the KV store and closing the connection.
Do you call:
Multiple times throughout your application or do you export your
kv
once and then access it through an import in your code?I see the Todo Showcase app exports the kv as
db
. And I can't find any reference to closing it.Or do you open it and close it within a given function? Example:
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions