Skip to content

Commit 58ea5e2

Browse files
committed
Add KeyValueSyncInterface::for_each.
1 parent cd3cc87 commit 58ea5e2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

tddb/td/db/BinlogKeyValue.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ class BinlogKeyValue final : public KeyValueSyncInterface {
220220
binlog_->lazy_sync(std::move(promise));
221221
}
222222

223+
void for_each(std::function<void(Slice, Slice)> func) final {
224+
auto lock = rw_mutex_.lock_write().move_as_ok();
225+
for (const auto &kv : map_) {
226+
func(kv.first, kv.second.first);
227+
}
228+
}
229+
223230
std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) final {
224231
auto lock = rw_mutex_.lock_write().move_as_ok();
225232
std::unordered_map<string, string, Hash<string>> res;

tddb/td/db/KeyValueSyncInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "td/utils/Promise.h"
1313
#include "td/utils/Slice.h"
1414

15+
#include <functional>
1516
#include <unordered_map>
1617

1718
namespace td {
@@ -35,6 +36,8 @@ class KeyValueSyncInterface {
3536

3637
virtual string get(const string &key) = 0;
3738

39+
virtual void for_each(std::function<void(Slice, Slice)> func) = 0;
40+
3841
virtual std::unordered_map<string, string, Hash<string>> prefix_get(Slice prefix) = 0;
3942

4043
virtual FlatHashMap<string, string> get_all() = 0;

0 commit comments

Comments
 (0)