diff options
| author | levlam <levlam@telegram.org> | 2024-01-23 19:26:43 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2024-01-23 19:26:43 +0300 |
| commit | 58ea5e22bc01aa5448340ed5582c9aaff516950b (patch) | |
| tree | b00ba768b6c235df01f79f1ee419b4e6b234b835 /tddb | |
| parent | cd3cc873f0e04403de7236efc3447a7dcd316423 (diff) | |
Add KeyValueSyncInterface::for_each.
Diffstat (limited to 'tddb')
| -rw-r--r-- | tddb/td/db/BinlogKeyValue.h | 7 | ||||
| -rw-r--r-- | tddb/td/db/KeyValueSyncInterface.h | 3 |
2 files changed, 10 insertions, 0 deletions
diff --git a/tddb/td/db/BinlogKeyValue.h b/tddb/td/db/BinlogKeyValue.h index 034db47b8..735e120d0 100644 --- a/tddb/td/db/BinlogKeyValue.h +++ b/tddb/td/db/BinlogKeyValue.h @@ -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; diff --git a/tddb/td/db/KeyValueSyncInterface.h b/tddb/td/db/KeyValueSyncInterface.h index d9e53cbf8..d4e43ffef 100644 --- a/tddb/td/db/KeyValueSyncInterface.h +++ b/tddb/td/db/KeyValueSyncInterface.h @@ -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; |
