KV().Del#
-
static inline void YR::KVManager::Del(const std::string &key, const DelParam &delParam = {})#
Deletes a key and its associated data, similar to Redis’s DEL command.
This function removes the specified key and its associated data. If the key does not exist, the operation is considered successful.
- Parameters:
key – The key to delete. If the key does not exist, the operation is considered successful.
delParam – Optional parameters for the delete operation, such as a custom trace ID.
- Throws:
Exception – Thrown in cluster mode if the delete operation fails.
-
static inline std::vector<std::string> YR::KVManager::Del(const std::vector<std::string> &keys, const DelParam &delParam = {})#
Deletes multiple keys and their associated data, similar to Redis’s DEL command.
This function removes the specified keys and their associated data. If a key does not exist, the operation for that key is considered successful.
int main() { YR::Config conf; conf.mode = Config::Mode::CLUSTER_MODE; YR::Init(conf); std::vector<std::string> keys{ "key1", "key2" }; std::vector<std::string> values{ "val1", "val2" }; YR::KV().Set(keys[0], values[0]); YR::KV().Set(keys[1], values[1]); std::vector<std::string> failedKeys = YR::KV().Del(keys); if (!failedKeys.empty()) { std::cout << "Failed to delete the following keys: "; for (const auto& key : failedKeys) { std::cout << key << " "; } std::cout << std::endl; } else { std::cout << "All keys deleted successfully." << std::endl; } return 0; }- Parameters:
keys – A list of keys to delete. The maximum number of keys is 10000. If a key does not exist, the operation for that key is considered successful.
delParam – Optional parameters for the delete operation, such as a custom trace ID.
- Throws:
YR::Exception – Thrown in cluster mode if the connection to the data system times out during the delete operation.
- Returns:
std::vector<std::string>, A vector containing the keys that failed to be deleted. If all keys are successfully deleted, the vector is empty.
The parameter structure is further described as follows:
-
struct DelParam#
Specifies parameters for a key to be deleted, such as setting a traceId.
Public Members
-
std::string traceId#
traceId
Custom traceId used for troubleshooting and performance optimization; only supported within the cloud environment; settings outside the cloud will not take effect. Maximum length is 36. Valid characters must match the regular expression:
^[a-zA-Z0-9\~\.\-\/_!@#%\^\&\*\(\)\+\=\:;]*$.
-
std::string traceId#