How to manage KV Store with Functions
Learn how to store, retrieve, and delete data using KV Store within your functions.
This guide shows you how to interact with KV Store from your functions to store, retrieve, and delete key-value data.
Go to KV Store referenceRequirements
Before you begin, make sure you have:
- Functions enabled in your application.
- A KV Store namespace created via Console or API.
Creating a function to interact with KV Store
Follow these steps to create a function that communicates with KV Store:
- Access Azion Console.
- On the upper-left corner, select Functions.
- Click + Function.
- Enter a name for your function, for example:
kv-store-handler. - Delete the placeholder code in the editor.
- Paste one of the code examples below based on your use case.
Storing data
This example demonstrates how to store different types of data in KV Store:
Retrieving data
This example shows how to retrieve data in different formats:
Retrieving multiple keys
Fetch multiple values in a single operation:
Retrieving data with metadata
Use getWithMetadata to retrieve both the value and its associated metadata:
Deleting data
Remove a key from the store:
Working with binary data
Store and retrieve binary data using ArrayBuffer:
Working with streams
For large data, use ReadableStream for efficient memory usage:
Using specific namespaces
Work with different namespaces for data isolation:
Instantiating the function
After creating your function, you need to instantiate it in your application:
Go to how to instantiate functions in your application