|
1 | 1 | // Copyright 2021 TiKV Project Authors. Licensed under Apache-2.0.
|
2 | 2 |
|
3 | 3 | #ifndef _TIKV_CLIENT_H_
|
4 |
| -#define _TIKV_CLIENT_H_ |
| 4 | +#define _TIKV_CLIENT_H_ |
5 | 5 |
|
6 |
| -#include "lib.rs.h" |
7 | 6 | #include <iostream>
|
8 | 7 | #include <optional>
|
9 | 8 |
|
| 9 | +#include "lib.rs.h" |
| 10 | + |
10 | 11 | namespace tikv_client {
|
11 | 12 |
|
12 | 13 | struct KvPair final {
|
13 |
| - std::string key; |
14 |
| - std::string value; |
| 14 | + std::string key; |
| 15 | + std::string value; |
15 | 16 |
|
16 |
| - KvPair(std::string &&key, std::string &&value); |
17 |
| - ffi::KvPair to_ffi(); |
| 17 | + KvPair(std::string &&key, std::string &&value); |
| 18 | + ffi::KvPair to_ffi(); |
18 | 19 | };
|
19 | 20 |
|
20 | 21 | class Transaction {
|
21 |
| -public: |
22 |
| - Transaction(::rust::cxxbridge1::Box<tikv_client_glue::Transaction> txn); |
23 |
| - std::optional<std::string> get(const std::string &key); |
24 |
| - std::optional<std::string> get_for_update(const std::string &key); |
25 |
| - std::vector<KvPair> batch_get(const std::vector<std::string> &keys); |
26 |
| - std::vector<KvPair> batch_get_for_update(const std::vector<std::string> &keys); |
27 |
| - std::vector<KvPair> scan(const std::string &start, Bound start_bound, const std::string &end, Bound end_bound, std::uint32_t limit); |
28 |
| - std::vector<std::string> scan_keys(const std::string &start, Bound start_bound, const std::string &end, Bound end_bound, std::uint32_t limit); |
29 |
| - void put(const std::string &key, const std::string &value); |
30 |
| - void batch_put(const std::vector<KvPair> &kvs); |
31 |
| - void remove(const std::string &key); |
32 |
| - void commit(); |
33 |
| -private: |
34 |
| - ::rust::cxxbridge1::Box<tikv_client_glue::Transaction> _txn; |
| 22 | + public: |
| 23 | + Transaction(::rust::cxxbridge1::Box<tikv_client_glue::Transaction> txn); |
| 24 | + std::optional<std::string> get(const std::string &key); |
| 25 | + std::optional<std::string> get_for_update(const std::string &key); |
| 26 | + std::vector<KvPair> batch_get(const std::vector<std::string> &keys); |
| 27 | + std::vector<KvPair> batch_get_for_update( |
| 28 | + const std::vector<std::string> &keys); |
| 29 | + std::vector<KvPair> scan(const std::string &start, Bound start_bound, |
| 30 | + const std::string &end, Bound end_bound, |
| 31 | + std::uint32_t limit); |
| 32 | + std::vector<std::string> scan_keys(const std::string &start, |
| 33 | + Bound start_bound, const std::string &end, |
| 34 | + Bound end_bound, std::uint32_t limit); |
| 35 | + void put(const std::string &key, const std::string &value); |
| 36 | + void batch_put(const std::vector<KvPair> &kvs); |
| 37 | + void remove(const std::string &key); |
| 38 | + void commit(); |
| 39 | + |
| 40 | + private: |
| 41 | + ::rust::cxxbridge1::Box<tikv_client_glue::Transaction> _txn; |
35 | 42 | };
|
36 | 43 |
|
37 | 44 | class TransactionClient {
|
38 |
| -public: |
39 |
| - TransactionClient(const std::vector<std::string> &pd_endpoints); |
40 |
| - Transaction begin(); |
41 |
| - Transaction begin_pessimistic(); |
42 |
| -private: |
43 |
| - ::rust::cxxbridge1::Box<tikv_client_glue::TransactionClient> _client; |
| 45 | + public: |
| 46 | + TransactionClient(const std::vector<std::string> &pd_endpoints); |
| 47 | + Transaction begin(); |
| 48 | + Transaction begin_pessimistic(); |
| 49 | + |
| 50 | + private: |
| 51 | + ::rust::cxxbridge1::Box<tikv_client_glue::TransactionClient> _client; |
44 | 52 | };
|
45 | 53 |
|
46 | 54 | class RawKVClient {
|
47 |
| -public: |
48 |
| - RawKVClient(const std::vector<std::string> &pd_endpoints); |
49 |
| - std::optional<std::string> get(const std::string &key,const std::uint64_t timeout); |
50 |
| - void put(const std::string &key, const std::string &value, const std::uint64_t timeout); |
51 |
| - void batch_put(const std::vector<KvPair> &kvs, const std::uint64_t timeout); |
52 |
| - void remove(const std::string &key, const std::uint64_t timeout); |
53 |
| - void remove_range(const std::string &start_key, const std::string &end_key, const std::uint64_t timeout); |
54 |
| - std::vector<KvPair> scan(const std::string &startKey, const std::string &endKey, std::uint32_t limit, const std::uint64_t timeout); |
55 |
| - |
56 |
| -private: |
57 |
| - ::rust::cxxbridge1::Box<tikv_client_glue::RawKVClient> _client; |
| 55 | + public: |
| 56 | + RawKVClient(const std::vector<std::string> &pd_endpoints); |
| 57 | + std::optional<std::string> get(const std::string &key, |
| 58 | + const std::uint64_t timeout); |
| 59 | + void put(const std::string &key, const std::string &value, |
| 60 | + const std::uint64_t timeout); |
| 61 | + void batch_put(const std::vector<KvPair> &kvs, const std::uint64_t timeout); |
| 62 | + void remove(const std::string &key, const std::uint64_t timeout); |
| 63 | + void remove_range(const std::string &start_key, const std::string &end_key, |
| 64 | + const std::uint64_t timeout); |
| 65 | + std::vector<KvPair> scan(const std::string &startKey, |
| 66 | + const std::string &endKey, std::uint32_t limit, |
| 67 | + const std::uint64_t timeout); |
| 68 | + |
| 69 | + private: |
| 70 | + ::rust::cxxbridge1::Box<tikv_client_glue::RawKVClient> _client; |
58 | 71 | };
|
59 | 72 |
|
60 |
| -} // namespace tikv_client |
| 73 | +} // namespace tikv_client |
61 | 74 |
|
62 |
| -#endif //_TIKV_CLIENT_H_ |
| 75 | +#endif //_TIKV_CLIENT_H_ |
0 commit comments