-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyvalue.h
42 lines (32 loc) · 1.29 KB
/
keyvalue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef SLOPE_KEYVALUE_H_
#define SLOPE_KEYVALUE_H_
#include <string>
#include <memory>
namespace slope {
namespace keyvalue {
class KeyValueService {
public:
virtual bool compare_and_swap(const std::string& key,
const std::string& oldv, const std::string& newv) = 0;
virtual bool set(const std::string& key, const std::string& val) = 0;
virtual bool get(const std::string& key, std::string& ret) = 0;
virtual bool wait_for(const std::string& key, std::string& ret) = 0;
virtual ~KeyValueService() = default;
using ptr = std::unique_ptr<KeyValueService>;
};
class KeyValuePrefixMiddleware: public KeyValueService {
public:
KeyValuePrefixMiddleware(std::unique_ptr<KeyValueService> impl, const std::string prefix);
virtual bool compare_and_swap(const std::string& key,
const std::string& oldv, const std::string& newv) final override;
virtual bool set(const std::string& key, const std::string& val) final override;
virtual bool get(const std::string& key, std::string& ret) final override;
virtual bool wait_for(const std::string& key, std::string& ret) final override;
using ptr = std::unique_ptr<KeyValueService>;
private:
std::unique_ptr<KeyValueService> impl_;
const std::string prefix_;
};
} // namespace keyvalue
} // namespace slope
#endif // SLOPE_KEYVALUE_H_