Read Data from Cloudflare Workers KV with BINDING.get
To access that data that we stored in our database, we use the .get() function. .get() is also an async function and we will need to await it.
Duration
1 min
Access
Pro
Transcript
Available
To access that data that we stored in our database, we use the .get() function. .get() is also an async function and we will need to await it.
Video Transcript
Instructor: Now that we've put something into our KV namespace, for instance, this value string here for this key, test-key, let's understand how to look something back up from that KV namespace.
In order to do that, I'll use MyFirstKv.get. GET is the complementary function to PUT, which takes in one argument, a key. In this case, that will be test-key. What I'll get back here is a promise that resolves to be value of this KV key. I'll say const value=await MyFirstKv.get("test-key").
Finally, I'll replace "Hello, worker" here with value, so I can see my KV value coming back from the KV namespace. To test this, I'll run wrangler publish. If I open this in browser, you can see that I get value back here. This is, of course, this value here, which was put as the value for test-key inside of MyFirstKv namespace.
What we have here is first, we're putting something into KV and then second, we're reading it back out of that same key in order to return it as the value inside of this response.
Duration
1 min
Access
Pro
Transcript
Available
Course lesson
Read Data from Cloudflare Workers KV with BINDING.get
To access that data that we stored in our database, we use the .get() function. .get() is also an async function and we will need to await it.
Access required
This lesson is available with an active egghead membership.