Loading...
Searching...
No Matches
kv_client.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
23#include "proto/kv/kv.pb.h"
24
25namespace resdb {
26
27// KVClient to send data to the kv server.
29 public:
30 KVClient(const ResDBConfig& config);
31
32 // Version-based interfaces.
33 // Obtain the current version before setting a new data
34 int Set(const std::string& key, const std::string& data, int version);
35
36 // Obtain the value with a specific version.
37 // If the version parameter is zero, it will return the data with the current
38 // version in the database. ValueInfo contains the version and its version.
39 // Return nullptr if there is an error.
40 std::unique_ptr<ValueInfo> Get(const std::string& key, int version);
41
42 // Obtain the latest values of the keys within [min_key, max_key].
43 // Keys should be comparable.
44 std::unique_ptr<Items> GetKeyRange(const std::string& min_key,
45 const std::string& max_key);
46
47 // Obtain the histories of `key` with the versions in [min_version,
48 // max_version]
49 std::unique_ptr<Items> GetKeyHistory(const std::string& key, int min_version,
50 int max_version);
51
52 // Obtain the top `top_number` histories of the `key`.
53 std::unique_ptr<Items> GetKeyTopHistory(const std::string& key,
54 int top_number);
55
56 // Non-version-based Interfaces.
57 // These interfaces are not compatible with the version-based interfaces
58 // above.
59 int Set(const std::string& key, const std::string& data);
60 std::unique_ptr<std::string> Get(const std::string& key);
61 std::unique_ptr<std::string> GetAllValues();
62 std::unique_ptr<std::string> GetRange(const std::string& min_key,
63 const std::string& max_key);
64};
65
66} // namespace resdb
std::string data
int Set(const std::string &key, const std::string &data, int version)
Definition kv_client.cpp:77
std::unique_ptr< Items > GetKeyTopHistory(const std::string &key, int top_number)
std::unique_ptr< std::string > GetRange(const std::string &min_key, const std::string &max_key)
Definition kv_client.cpp:62
std::unique_ptr< Items > GetKeyHistory(const std::string &key, int min_version, int max_version)
std::unique_ptr< ValueInfo > Get(const std::string &key, int version)
Definition kv_client.cpp:87
std::unique_ptr< Items > GetKeyRange(const std::string &min_key, const std::string &max_key)
std::unique_ptr< std::string > GetAllValues()
Definition kv_client.cpp:50