Last update:2024-09-24 15:05:34
Edge KV is a globally distributed key-value storage service offered by CDNetworks Edge Application, designed for scenarios that require low latency, high availability, and strong data consistency. It allows you to store data on edge PoPs closer to your users. Edge KV is particularly well-suited for scenarios where developers write data infrequently, while edge functions read data frequently.
For example, you can write data to Edge KV through the console and then use the built-in Runtime API in Edge Cloud Apps Functions to read data at high frequency for processing client requests. Combining Edge Cloud Apps Functions and Edge KV allows you to quickly build lightweight BaaS services, API gateways, and other services and features.
Before using Edge KV, you need to create a namespace to store your data.
A namespace is a logical container used to organize and isolate data within Edge KV. You can store data from different applications or services in separate namespaces to prevent naming conflicts and enhance data security. Each namespace has a unique name used to identify and access the data within that namespace. Namespace names must be unique across the entire CDNetworks Edge Application platform.
You can easily create an Edge KV namespace through the CDNetworks Console.
my-app-data
. The namespace name must be globally unique, have a length of 4 to 32 characters, and can only contain numbers, lowercase English letters, and underscores.Parameter Description
Property | Description |
---|---|
Mode Type | • Global Mode: Data is stored centrally, with the edge caching necessary data and managing data freshness. When data is missing at the edge, it’s automatically pulled from the central node or updated via push notifications. • Local Mode: Data is only stored, read, written, and deleted locally at the edge node. Requests do not go through the central node, eliminating the need to manage data freshness. • Mirror Mode: The central node pushes all data to the edge in advance, creating mirrored copies of the central data across multiple edge nodes. Edge nodes do not need to manage data freshness or pull data from the central node as updates are automatically pushed from the central node. |
Storage Duration | The maximum storage period for keys within the KV namespace. The default is permanent storage for Global Mode; for Local and Mirrored Mode, the default is 30 days. |
Space Capacity | The storage capacity of the namespace you created. If you require a different capacity, please contact the CDNetworks technical support team. |
For more information on namespace parameters, please refer to our Usage Limits documentation.
After creating a namespace, you can view and manage its details in the Space Management interface.
You can add and manage key-value pairs in your Edge KV namespace in two ways:
The CDNetworks console allows you to add, view, and delete Edge KV data intuitively.
Note
The expiration time must be less than or equal to the Storage Duration of the current namespace. You can upload any key-value pair, as long as its length meets the platform’s requirements.
After adding the key-value pair, you can view it in the Space Content area. You can click the Download Full Value button in the right-side operation bar to view the complete value. To delete a key-value pair, click the Delete button. After confirming the deletion, the system will immediately delete the selected key value. You can also select multiple keys and click the Batch Delete button to perform a batch deletion.
Note: Deleting a key takes effect immediately across the entire platform and is permanent. Ensure you have backed up important data and carefully confirm the necessity of deletion to avoid impacting your services and functions.
You can achieve more flexible and granular management of Edge KV through the Runtime API built into Edge Cloud Apps Function Compute. This allows you to automate operations and integrate seamlessly with other services. Additionally, you can directly write and debug code in CloudIDE to ensure that the code functions as expected.
Note
Before managing Edge KV data using the API, ensure you have already created a namespace in the console.
For detailed API usage instructions, please refer to the Edge KV Runtime API documentation.
For example:
Call the constructor, passing in the namespace to create an Edge KV instance object.
const edgeKv = new EdgeKV({ namespace: "your-namespace" });
The namespace
is the name of the storage space you created in the console, which can be found in the Space List.
After successfully creating the instance object, you can call the following built-in APIs to implement various functions based on your needs:
API | Function |
---|---|
get() |
Retrieves data from the namespace. |
put() |
Creates a new key-value pair or updates the value of an existing key. |
list() |
Lists keys in the namespace that meet specified criteria. |
count() |
Counts the number of keys in the namespace that meet specified criteria. |
delete() |
Deletes the specified key and its corresponding value from the namespace. |
You can delete namespaces you no longer need through the CDNetworks console. Please note that deleting a namespace permanently removes all data within it, and this operation is irreversible,which will impact all features that use values within that namespace.