147
• Line 9-22: All params are put into config (the cfg instance) one after
another (using function dedicated for the type), and each is checked
if was stored successful (PMEMKV_STATUS_OK is returned when no
errors occurred).
A Phonebook Example
Listing 9-2 shows a simple phonebook example implemented using the pmemkv C++
API v0.9. One of the main intentions of pmemkv is to provide a familiar API similar to
the other key-value stores. This makes it very intuitive and easy to use. We will reuse the
config_setup() function from Listing 9-1.
Listing 9-2. A simple phonebook example using the pmemkv C++ API
37
#include
38
#include
39
#include
40
#include
41
#include "pmemkv_config.h"
42
43
using namespace pmem::kv;
44
45
auto PATH = "/daxfs/kvfile";
46
const uint64_t FORCE_CREATE = 1;
47
const uint64_t SIZE = 1024 ∗ 1024 ∗ 1024; // 1 Gig
48
49
int main() {
50
// Prepare config for pmemkv database
51
pmemkv_config ∗cfg = config_setup(PATH, FORCE_CREATE, SIZE);
52
assert(cfg != nullptr);
53
54
// Create a key-value store using the "cmap" engine.
55
db kv;
56
57
if (kv.open("cmap", config(cfg)) != status::OK) {
58
std::cerr << db::errormsg() << std::endl;
Chapter 9 pmemkv: a persistent in- memory key-value store
Précédent

- 172/457

Suivant