-
Notifications
You must be signed in to change notification settings - Fork 8
/
kvstore_example.ts
64 lines (50 loc) · 1.58 KB
/
kvstore_example.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { getClient } from "./client_loader";
import { log } from "./utils";
async function setKey(client, key) {
const res = await client.kvstore.set(key);
log("================= Setting the key =================");
log(res);
log("================= Setting the key =================");
}
async function listAllKeys(client) {
const res = await client.kvstore.list();
log("================= Listing all keys =================");
log(res);
log("================= Listing all keys =================");
}
async function getKey(client, key) {
const res = await client.kvstore.get(key);
log("================= Getting key =================");
log(res);
log("================= Getting key =================");
}
async function removeKey(client, key) {
const res = await client.kvstore.remove(key);
log("================= Removing key =================");
log(res);
log("================= Removing key =================");
}
/*
KVStore example usage:
*/
async function main() {
//For creating grid3 client with KVStore, you need to specify the KVStore storage type in the pram:
const gridClient = await getClient();
//then every module will use the KVStore to save its configuration and restore it.
// set key
const key = "hamada";
const exampleObj = {
key1: "value1",
key2: 2,
};
//Set key
await setKey(gridClient, { key, value: JSON.stringify(exampleObj) });
//List all keys
await listAllKeys(gridClient);
//Get key
await getKey(gridClient, { key });
//Remove key
await removeKey(gridClient, { key });
await gridClient.disconnect();
}
main();