Add KeyValueSyncInterface::for_each.

This commit is contained in:
levlam 2024-01-23 19:26:43 +03:00
parent cd3cc873f0
commit 58ea5e22bc
2 changed files with 10 additions and 0 deletions

View File

@ -220,6 +220,13 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
binlog_->lazy_sync(std::move(promise));
}
void for_each(std::function<void(Slice, Slice)> func) final {
auto lock = rw_mutex_.lock_write().move_as_ok();
for (const auto &kv : map_) {
func(kv.first, kv.second.first);
}
}
std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) final {
auto lock = rw_mutex_.lock_write().move_as_ok();
std::unordered_map<string, string, Hash<string>> res;

View File

@ -12,6 +12,7 @@
#include "td/utils/Promise.h"
#include "td/utils/Slice.h"
#include <functional>
#include <unordered_map>
namespace td {
@ -35,6 +36,8 @@ class KeyValueSyncInterface {
virtual string get(const string &key) = 0;
virtual void for_each(std::function<void(Slice, Slice)> func) = 0;
virtual std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) = 0;
virtual FlatHashMap<string, string> get_all() = 0;