KV().Set#
-
static inline void YR::KVManager::Set(const std::string &key, const char *value, ExistenceOpt existence = ExistenceOpt::NONE)#
Sets the value of a key.
std::string result{"result"}; YR::KV().Set("key", result.c_str()); // setVal
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.value – [in] Binary data to be stored. Cloud-out storage is limited to a maximum of 100M.
existence – [in] Determines if the key allows repeated writes. Optional parameters are
YR::ExistenceOpt::NONE(allow, default) andYR::ExistenceOpt::NX(do not allow).
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const char *value, size_t len, ExistenceOpt existence = ExistenceOpt::NONE)#
Sets the value of a key.
std::string result{"result"}; auto size = result.size() + 1; YR::KV().Set("key", result.c_str(), size); // setValLen
The value is of type char*, and the length can be specified. This interface is typically used when the value contains a null character ‘\0’, such as data serialized by msgpack.
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.value – [in] Binary data to be stored.
len – [in] The length of the binary data. The user must ensure the correctness of the len value.
existence – [in] Determines if the key allows repeated writes. Optional parameters are YR::ExistenceOpt::NONE (allow, default) and
YR::ExistenceOpt::NX(do not allow).
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const std::string &str, ExistenceOpt existence = ExistenceOpt::NONE)#
Sets the value of a key.
std::string result{"result"}; YR::KV().Set("key", result);
The value is of type string, and the length can be accurately determined by string.size(), so len is not required.
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.value – [in] The string to be stored.
existence – [in] Determines if the key allows repeated writes. Optional parameters are
YR::ExistenceOpt::NONE(allow, default) andYR::ExistenceOpt::NX(do not allow).
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const char *value, SetParam setParam)#
Sets the value of a key.
YR::SetParam setParam; setParam.ttlSecond = 0; setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT; setParam.existence = YR::ExistenceOpt::NONE; std::string result{"result"}; YR::KV().Set("key", result.c_str(), setParam);
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.val – [in] Binary data to be stored. Cloud-out storage is limited to a maximum of 100M.
setParam – [in] Configures attributes such as reliability for the object.
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const char *value, size_t len, SetParam setParam)#
Sets the value of a key.
YR::SetParam setParam; setParam.ttlSecond = 0; setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT; setParam.existence = YR::ExistenceOpt::NONE; std::string result{"result"}; auto size = result.size() + 1; YR::KV().Set("key", result.c_str(), size, setParam);
The value is of type char*, and the length can be specified. This interface is typically used when the value contains a null character ‘\0’, such as data serialized by msgpack.
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.val – [in] Binary data to be stored.
len – [in] The length of the binary data. The user must ensure the correctness of the len value.
setParam – [in] Configures attributes such as reliability for the object.
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const std::string &str, SetParam setParam)#
Sets the value of a key.
YR::SetParam setParam; setParam.ttlSecond = 0; setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT; setParam.existence = YR::ExistenceOpt::NONE; YR::KV().Set("kv-key", "kv-value", setParam);
The value is of type string, and the length can be accurately determined by string.size(), so len is not required.
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.value – [in] The string to be stored.
setParam – [in] Configures attributes such as reliability for the object.
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const char *val, SetParamV2 setParamV2)#
Sets the value of a key.
YR::SetParamV2 setParam; setParam.ttlSecond = 0; setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT; setParam.existence = YR::ExistenceOpt::NONE; setParam.cacheType = YR::CacheType::MEMORY; std::string result{"result"}; YR::KV().Set("key", result.c_str(), setParam);
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.val – [in] Binary data to be stored. Cloud-out storage is limited to a maximum of 100M.
setParamV2 – [in] Configures attributes such as reliability for the object.
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const char *val, size_t len, SetParamV2 setParamV2)#
Sets the value of a key.
YR::SetParamV2 setParam; setParam.ttlSecond = 0; setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT; setParam.existence = YR::ExistenceOpt::NONE; setParam.cacheType = YR::CacheType::MEMORY; std::string result{"result"}; auto size = result.size() + 1; YR::KV().Set("key", result.c_str(), size, setParam);
The value is of type char*, and the length can be specified. This interface is typically used when the value contains a null character ‘\0’, such as data serialized by msgpack.
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.val – [in] Binary data to be stored.
len – [in] The length of the binary data. The user must ensure the correctness of the len value.
setParamV2 – [in] Configures attributes such as reliability for the object.
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
static inline void YR::KVManager::Set(const std::string &key, const std::string &str, SetParamV2 setParamV2)#
Sets the value of a key.
YR::SetParamV2 setParam; setParam.ttlSecond = 0; setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT; setParam.existence = YR::ExistenceOpt::NONE; setParam.cacheType = YR::CacheType::MEMORY; YR::KV().Set("kv-key", "kv-value", setParam);
The value is of type string, and the length can be accurately determined by string.size(), so len is not required.
- Parameters:
key – [in] A key used to identify the stored data. Must not be empty. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.value – [in] The string to be stored.
setParamV2 – [in] Configures attributes such as reliability for the object.
- Throws:
1001: Parameter error. Detailed error information will be provided.
4206: Key already exists. If existence is set to
YR::ExistenceOpt::NXand one or more keys in the list have been previously set or written.Other exceptions may be thrown due to errors during the
Setoperation, with detailed descriptions provided in the error message.
-
struct SetParam#
Configures attributes for an object, such as reliability.
Public Members
-
WriteMode writeMode = WriteMode::NONE_L2_CACHE#
Write mode.
Sets the reliability of data. When the server configuration supports a secondary cache (e.g., Redis), this setting ensures data reliability. Default value: YR::WriteMode::NONE_L2_CACHE
-
uint32_t ttlSecond = 0#
Time-to-Live (TTL) in seconds.
Specifies the duration for which the data will be retained before being deleted. Default value: 0, meaning the key will persist until explicitly deleted using the Del interface.
-
ExistenceOpt existence = ExistenceOpt::NONE#
Existence option.
Determines if the key allows repeated writes. Optional parameters: YR::ExistenceOpt::NONE (allow, default) and YR::ExistenceOpt::NX (do not allow). Default value: YR::ExistenceOpt::NONE.
-
std::string traceId#
Trace ID.
A custom trace ID used for troubleshooting and performance optimization. Only supported within the cloud environment; settings outside the cloud will not take effect. Maximum length: 36. Valid characters must match the regular expression: ^[a-zA-Z0-9.-\/_!#%\^&*()+=\:;]*$
-
WriteMode writeMode = WriteMode::NONE_L2_CACHE#
-
struct SetParamV2#
Configures attributes for an object, such as reliability.
Public Members
-
WriteMode writeMode = WriteMode::NONE_L2_CACHE#
Write mode.
Sets the reliability of data. When the server configuration supports a secondary cache (e.g., Redis), this setting ensures data reliability. Default value: YR::WriteMode::NONE_L2_CACHE
-
uint32_t ttlSecond = 0#
Time-to-Live (TTL) in seconds.
Specifies the duration for which the data will be retained before being deleted. Default value: 0, meaning the key will persist until explicitly deleted using the Del interface.
-
ExistenceOpt existence = ExistenceOpt::NONE#
Existence option.
Determines if the key allows repeated writes. Optional parameters: YR::ExistenceOpt::NONE (allow, default) and YR::ExistenceOpt::NX (do not allow). Default value: YR::ExistenceOpt::NONE.
-
std::string traceId#
Trace ID.
A custom trace ID used for troubleshooting and performance optimization. Only supported within the cloud environment; settings outside the cloud will not take effect. Maximum length: 36. Valid characters must match the regular expression: ^[a-zA-Z0-9.-\/_!#%\^&*()+=\:;]*$
-
CacheType cacheType = CacheType::MEMORY#
Cache type.
Specifies whether the data is allocated to memory or disk. Optional parameters: YR::CacheType::Memory (memory) and YR::CacheType::Disk (disk). Default value: YR::CacheType::Memory.
-
std::unordered_map<std::string, std::string> extendParams#
Extended parameters.
Configures additional parameters beyond those specified above
-
WriteMode writeMode = WriteMode::NONE_L2_CACHE#
-
enum class YR::WriteMode : int#
Write Mode.
Sets the reliability of data. When the server configuration supports a secondary cache (e.g., Redis), this setting ensures data reliability.
Values:
-
enumerator NONE_L2_CACHE#
Do not write to the secondary cache.
-
enumerator WRITE_THROUGH_L2_CACHE#
Synchronously write data to the secondary cache to ensure reliability.
-
enumerator WRITE_BACK_L2_CACHE#
Asynchronously write data to the secondary cache to ensure reliability.
-
enumerator NONE_L2_CACHE_EVICT#
Do not write to the secondary cache, and the data may be evicted when system resources are insufficient.
-
enumerator NONE_L2_CACHE#