Create a KV Namespace

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.

What is Namespaces?

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.

Creating a Namespace

You can easily create an Edge KV namespace through the CDNetworks Console.

  1. Log in to the CDNetworks Console, select the Edge Application product, locate the Edge Key-Value menu, and click Namespace List.
  2. Click the Create Space button on the page, and a namespace creation window will pop up.
  3. On the namespace creation page, you need to fill in the following information:
  • Bucket Name: Enter the desired name for your namespace, for example, 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.
  • Space Alias: Provide a user-friendly alias for the namespace, to easily distinguish it in the console. The space alias can be 6 to 64 characters long and may include Chinese characters (each occupying two characters), numbers, uppercase and lowercase English letters, and underscores.
  • Mode Type: Choose the appropriate mode type based on your use case to determine how data is stored and accessed. Edge KV offers three modes: Global Mode, Local Mode, and Mirrored Mode.
  • Storage Duration: Set the maximum storage period for keys within the KV namespace. The default for Global Mode is permanent storage, while Local and Mirrored Modes default to 30 days. You can choose a suitable storage duration based on your specific needs. Each key’s expiration time cannot exceed this period.

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.

  1. Click the OK button to complete the namespace creation.


Viewing Your Namespace

After creating a namespace, you can view and manage its details in the Space Management interface.

  1. Log in to the CDNetworks Console, select the Edge Application product, locate the Edge Key-Value menu, and click Namespace List.
  2. Find the namespace you want to manage and click the Space Management button on the right side.
  3. In the Basic Information section, you can view the name, alias, mode, and remarks of the namespace. You can also modify the namespace alias and add remarks here.
  4. The Space Properties section displays the properties of your namespace, including the storage duration, space size, key length limit, and value length limit.
  5. The Space Content section displays the actual data stored in your namespace. You can add, view, and delete KV data here.


Adding and Managing Namespace Content

You can add and manage key-value pairs in your Edge KV namespace in two ways:

Via the Console

The CDNetworks console allows you to add, view, and delete Edge KV data intuitively.

  1. To add a new key-value pair, click the Add button in the Space Content section. This will open a window where you can enter the key, value, and expiration time.
  2. In the Add Key-Value window, enter the key, value, and expiration time.

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.


  1. 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.


Via Edge Cloud Apps 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:

  1. 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.

  2. 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.

Deleting a 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.

  1. Log in to the CDNetworks Console, select the Edge Application product, locate the Edge Key-Value menu, and click Space List.
  2. In the namespace list, locate the namespace you wish to delete.
  3. Click the Delete button to the right of the namespace.
  4. A confirmation dialog will appear prompting you to confirm the deletion of the namespace.
  5. Click the Confirm button to delete the namespace.


Notes

  • To enhance data isolation and security, it is recommended to create separate namespaces for different applications or services, and use clear and easy-to-understand namespace names for easy identification and management.
  • Regularly back up your Edge KV data to ensure you can quickly recover data in case of accidental loss, ensuring business continuity.
Is the content of this document helpful to you?
Yes
I have suggestion
Submitted successfully! Thank you very much for your feedback, we will continue to strive to do better!