KV().Write

KV().Write#

template<typename T>
static inline void YR::KVManager::Write(const std::string &key, const T &value, ExistenceOpt existence = ExistenceOpt::NONE)#

Writes the value of a key.

int count = 100;
Counter c("Counter1-", count);
try {
    YR::KV().Write<Counter>(c.name, c);
} catch (YR::Exception &e) {
    // handle exception...
}

Template Parameters:

T – The type of the object.

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] Data to be stored in the data system.

  • 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:

Exception

  • 1001: Parameter error. Detailed error information will be provided.

  • 4206: Key already exists. If existence is set to YR::ExistenceOpt::NX and one or more keys in the list have been previously set or written.

  • Other exceptions may be thrown due to errors during the Set operation, with detailed descriptions provided in the error message.

template<typename T>
static inline void YR::KVManager::Write(const std::string &key, const T &value, SetParam setParam)#

Writes the value of a key.

int count = 100;
Counter c("Counter1-", count);
YR::SetParam setParam;
setParam.ttlSecond = 0;
setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT;
setParam.existence = YR::ExistenceOpt::NONE;
try {
    YR::KV().Write<Counter>(c.name, c, setParam);
} catch (YR::Exception &e) {
    // handle exception...
}

Template Parameters:

T – The type of the object.

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] Data to be stored in the data system.

  • setParam[in] Configures attributes such as reliability for the object.

Throws:

Exception

  • 1001: Parameter error. Detailed error information will be provided.

  • 4206: Key already exists. If existence is set to YR::ExistenceOpt::NX and one or more keys in the list have been previously set or written.

  • Other exceptions may be thrown due to errors during the Set operation, with detailed descriptions provided in the error message.

template<typename T>
static inline void YR::KVManager::Write(const std::string &key, const T &value, SetParamV2 setParam)#

Writes the value of a key.

int count = 100;
Counter c("Counter1-", count);
YR::SetParamV2 setParam;
setParam.ttlSecond = 0;
setParam.writeMode = YR::WriteMode::NONE_L2_CACHE_EVICT;
setParam.existence = YR::ExistenceOpt::NONE;
setParam.cacheType = YR::CacheType::MEMORY;
try {
    YR::KV().Write<Counter>(c.name, c, setParam);
} catch (YR::Exception &e) {
    // handle exception...
}

Template Parameters:

T – The type of the object.

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] Data to be stored in the data system.

  • setParamV2[in] Configures attributes such as reliability for the object.

Throws:

Exception

  • 1001: Parameter error. Detailed error information will be provided.

  • 4206: Key already exists. If existence is set to YR::ExistenceOpt::NX and one or more keys in the list have been previously set or written.

  • Other exceptions may be thrown due to errors during the Set operation, with detailed descriptions provided in the error message.