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 is enabled, key-value pairs can be stored in the cache. For details about cache specifications, see MAX_CACHE_SIZE. For details about the number of key-value pairs that can be stored in an application, see MAX_KV_SUM.

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()

  1. int ClearKVCache (void )

Description:

Clears all key-value pairs from the cache.

Attention:

This function is available only if FEATURE_KV_CACHE is enabled.

Returns:

Returns 0 if the operation is successful; returns -1 otherwise.

UtilsDeleteValue()

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

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

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