Read Data from Cloudflare Workers KV with BINDING.get

Share this video with your friends

Social Share Links

Send Tweet
Published 3 years ago
Updated 3 years ago

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.

Instructor: [0:00] 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.

[0:11] 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").

[0:38] 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.

[1:01] 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.

egghead
egghead
~ 21 seconds ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today