# Kv\_store ## **Overview** Provides functions for obtaining, setting, and deleting a key-value pair. Key-value pairs can be permanently stored in the file system. If [FEATURE\_KV\_CACHE](utils_config.md#gad3d71669516ef0bb50e2b105507a6b29) is enabled, key-value pairs can be stored in the cache. For details about cache specifications, see [MAX\_CACHE\_SIZE](utils_config.md#ga6c8469dfe973ac952cf40394bd2c160b). For details about the number of key-value pairs that can be stored in an application, see [MAX\_KV\_SUM](utils_config.md#ga4f258bd7d7d52c6770cce77f3e16ce72). **Since:** 1.0 **Version:** 1.0 ## **Summary** ## Files

File Name

Description

kv_store.h

Provides functions for obtaining, setting, and deleting a key-value pair.

## Functions

Function Name

Description

UtilsGetValue (const char *key, char *value, unsigned int len)

int

Obtains the value matching a specified key from the file system or cache.

UtilsSetValue (const char *key, const char *value)

int

Adds or updates the value matching a specified key in the file system or cache.

UtilsDeleteValue (const char *key)

int

Deletes the value matching a specified key from the file system or cache.

ClearKVCache (void)

int

Clears all key-value pairs from the cache.

## **Details** ## **Function Documentation** ## ClearKVCache\(\) ``` int ClearKVCache (void ) ``` **Description:** Clears all key-value pairs from the cache. **Attention:** This function is available only if [FEATURE\_KV\_CACHE](utils_config.md#gad3d71669516ef0bb50e2b105507a6b29) is enabled. **Returns:** Returns **0** if the operation is successful; returns **-1** otherwise. ## UtilsDeleteValue\(\) ``` int UtilsDeleteValue (const char * key) ``` **Description:** Deletes the value matching a specified key from the file system or cache. **Parameters:**

Name

Description

key Indicates the key whose value is to be deleted. It allows only lowercase letters, digits, underscores (_), and dots (.). Its length cannot exceed 32 bytes (including the end-of-text character in the string).
**Returns:** Returns **0** if the operation is successful; returns **-9** if a parameter is incorrect; returns **-1** in other scenarios. ## UtilsGetValue\(\) ``` int UtilsGetValue (const char * key, char * value, unsigned int len ) ``` **Description:** Obtains the value matching a specified key from the file system or cache. **Parameters:**

Name

Description

key Indicates the key to be indexed. It allows only lowercase letters, digits, underscores (_), and dots (.). Its length cannot exceed 32 bytes (including the end-of-text character in the string).
value Indicates the buffer for storing the value that matches the key. This is an output parameter.
len Indicates the size of the value space in the buffer.
**Returns:** Returns the length of the value if the operation is successful; returns **-9** if a parameter is incorrect; returns **-1** in other scenarios; returns **0** if the value is obtained from the cache. ## UtilsSetValue\(\) ``` int UtilsSetValue (const char * key, const char * value ) ``` **Description:** Adds or updates the value matching a specified key in the file system or cache. **Parameters:**

Name

Description

key Indicates the key whose value is to be added or updated. It allows only lowercase letters, digits, underscores (_), and dots (.). Its length cannot exceed 32 bytes (including the end-of-text character in the string).
value Indicates the value to be added or updated. Its length cannot exceed 128 bytes (including the end-of-text character in the string).
**Returns:** Returns **0** if the operation is successful; returns **-9** if a parameter is incorrect; returns **-1** in other scenarios.