1 //
2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 #pragma once
8 
9 #include "td/actor/PromiseFuture.h"
10 
11 #include "td/utils/common.h"
12 #include "td/utils/Slice.h"
13 
14 #include <unordered_map>
15 
16 namespace td {
17 
18 class KeyValueSyncInterface {
19  public:
20   // SeqNo is used to restore total order on all write queries.
21   // Some implementations may return 0 as SeqNo.
22   using SeqNo = uint64;
23 
24   KeyValueSyncInterface() = default;
25   KeyValueSyncInterface(const KeyValueSyncInterface &) = delete;
26   KeyValueSyncInterface &operator=(const KeyValueSyncInterface &) = delete;
27   KeyValueSyncInterface(KeyValueSyncInterface &&) = default;
28   KeyValueSyncInterface &operator=(KeyValueSyncInterface &&) = default;
29   virtual ~KeyValueSyncInterface() = default;
30 
31   virtual SeqNo set(string key, string value) = 0;
32 
33   virtual bool isset(const string &key) = 0;
34 
35   virtual string get(const string &key) = 0;
36 
37   virtual std::unordered_map<string, string> prefix_get(Slice prefix) = 0;
38 
39   virtual std::unordered_map<string, string> get_all() = 0;
40 
41   virtual SeqNo erase(const string &key) = 0;
42 
43   virtual void erase_by_prefix(Slice prefix) = 0;
44 
45   virtual void force_sync(Promise<> &&promise) = 0;
46 
47   virtual void close(Promise<> promise) = 0;
48 };
49 
50 }  // namespace td
51