Skip to content
This repository was archived by the owner on Mar 22, 2023. It is now read-only.

Commit 6cb1237

Browse files
committed
Add interactive example
1 parent 094bc84 commit 6cb1237

5 files changed

Lines changed: 37 additions & 65 deletions

File tree

examples/basic_example.py

Lines changed: 29 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2020, Intel Corporation
1+
# Copyright 2021, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions
@@ -28,74 +28,45 @@
2828
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31-
import pmemkv
32-
import json
33-
34-
35-
def callback(key):
36-
mem_view = memoryview(key)
37-
print(mem_view.tobytes().decode())
38-
39-
40-
print("Loading config from json file")
41-
config = None
42-
with open("vsmap_conf.json") as f:
43-
config = json.load(f)
44-
45-
print(f"Starting engine with config: {config}")
46-
db = pmemkv.Database("vsmap", config)
47-
print("Put new key")
48-
db.put("key1", "value1")
49-
assert db.count_all() == 1
31+
# Usage:
32+
# insert element: 'basic_example.py --path path_to_db --insert key value'
33+
# lookup element: 'basic_example.py --path path_to_db --lookup key'
34+
# print all elemnets: 'basic_example.py --path path_to_db --iterate'
5035

51-
print("Reading key back")
52-
assert db.get_string("key1") == "value1"
53-
54-
print("Iterating existing keys")
55-
db.put("key2", "value2")
56-
db.put("key3", "value3")
57-
db.get_keys(lambda k: print(f"visited: {memoryview(k).tobytes().decode()}"))
36+
import pmemkv
37+
import argparse
5838

59-
print("Get single value")
60-
db.get("key1", callback)
39+
def callback_kv(key, value):
40+
print("key: ", memoryview(key).tobytes().decode(), " value: ", memoryview(value).tobytes().decode())
6141

62-
print("Get single value and key in lambda expression")
63-
key = "key1"
64-
db.get(
65-
key,
66-
lambda v, k=key: print(
67-
f"key: {k} with value: " f"{memoryview(v).tobytes().decode()}"
68-
),
69-
)
42+
def callback_v(value):
43+
print(memoryview(value).tobytes().decode())
7044

71-
print("Get first 2 bytes of the value (without copying the entire value) and the key in a lambda expression")
72-
db.get(
73-
key,
74-
lambda v, k=key: print(
75-
f"key: {k} with first 2 bytes of the value: " f"{(memoryview(v)[0:2]).tobytes().decode()}"
76-
),
77-
)
45+
parser = argparse.ArgumentParser()
46+
parser.add_argument('--path')
7847

79-
print("Removing existing key")
80-
db.remove("key1")
81-
assert not db.exists("key1")
48+
group = parser.add_mutually_exclusive_group(required=True)
49+
group.add_argument('--lookup', nargs=1, metavar=('key'))
50+
group.add_argument('--insert', nargs=2, metavar=('key', 'value'))
51+
group.add_argument('--iterate', action='store_true')
8252

83-
print("Stopping engine")
84-
db.stop()
53+
args = parser.parse_args()
8554

8655
print("Configuring engine")
8756
config = {}
88-
config["path"] = "/dev/shm"
89-
config["size"] = 1073741824
57+
config["path"] = "/dev/shm/t1"
58+
config["size"] = 10485760
59+
config["create_if_missing"] = 1
9060

9161
print(f"Starting engine with config: {config}")
92-
db = pmemkv.Database("vsmap", config)
93-
94-
print("Put new key")
95-
db.put("key1", "value1")
96-
97-
print("Get single value")
98-
db.get("key1", callback)
62+
db = pmemkv.Database("cmap", config)
63+
64+
if args.lookup:
65+
db.get(args.lookup[0], callback_v)
66+
elif args.insert:
67+
db.put(args.insert[0], args.insert[1])
68+
else:
69+
db.get_all(callback_kv)
9970

10071
print("Stopping engine")
10172
db.stop()

utils/docker/images/Dockerfile.fedora-31

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ RUN dnf update -y \
7474
wget \
7575
which \
7676
python3-pip \
77+
libatomic \
7778
&& dnf clean all
7879

7980
RUN pip3 install pytest setuptools wheel

utils/docker/images/install-libpmemobj-cpp.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ set -e
4040
PREFIX=/usr
4141
PACKAGE_TYPE=$1
4242

43-
# master: Merge pull request #652 from ldorau/Create-separate-Docker-images-for-v1.10-branch
44-
LIBPMEMOBJ_CPP_VERSION="006137044243981f4760ae220101a43cf97bcf2d"
43+
# master: Merge pull request #1062 from igchor/fix_parallel_xexec
44+
LIBPMEMOBJ_CPP_VERSION='485353b9c2fdbaf57607dcd83551664cbc3cd963'
4545

4646
git clone https://github.com/pmem/libpmemobj-cpp --shallow-since=2019-10-02
4747
cd libpmemobj-cpp
@@ -50,7 +50,7 @@ git checkout $LIBPMEMOBJ_CPP_VERSION
5050
mkdir build
5151
cd build
5252

53-
cmake .. -DCPACK_GENERATOR="$PACKAGE_TYPE" -DCMAKE_INSTALL_PREFIX=$PREFIX
53+
cmake .. -DCPACK_GENERATOR="$PACKAGE_TYPE" -DCMAKE_INSTALL_PREFIX=$PREFIX -DTESTS_USE_VALGRIND=0
5454

5555
if [ "$PACKAGE_TYPE" = "" ]; then
5656
make -j$(nproc) install

utils/docker/images/install-pmdk.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ set -e
3939
PREFIX=/usr
4040
PACKAGE_TYPE=$1
4141

42-
# stable-1.8: common: fix build on GitHub Actions
43-
PMDK_VERSION="eeb8fd86c6c72f4607a22a1e9d9f7da31be8af2a"
42+
# stable-1.10
43+
PMDK_VERSION="1.10"
4444

4545
git clone https://github.com/pmem/pmdk --shallow-since=2019-09-26
4646
cd pmdk

utils/docker/images/prepare-pmemkv.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ set -e
3939
PREFIX=/usr
4040
PACKAGE_TYPE=$1
4141

42-
# master: Merge pull request #602 from ldorau/Fix-setting-compilers--do-not-mix-gcc-with-clang
43-
current_pmemkv_version="5aff9f197e2e3eaae7f419c04ab9e2fc98309eed"
42+
# master: Merge pull request #985 from JanDorniak99/add_test_case_with_zero_filled_string
43+
current_pmemkv_version="e57429f4640278b7eead80f89832ba1136356c81"
4444
# stable-1.0: Merge pull request #528 from ldorau/Do-not-add-pmemkv_config...; 14.11.2019
4545
stable_1_pmemkv_version="a3735b5393f0d5411ef8a2468b36d2a1ed00c0a1"
4646
# stable-1.1: Version 1.1

0 commit comments

Comments
 (0)