-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcluster-simple.c
35 lines (29 loc) · 962 Bytes
/
cluster-simple.c
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
#include <valkey/cluster.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
UNUSED(argc);
UNUSED(argv);
struct timeval timeout = {1, 500000}; // 1.5s
valkeyClusterContext *cc = valkeyClusterContextInit();
valkeyClusterSetOptionAddNodes(cc, "127.0.0.1:7000");
valkeyClusterSetOptionConnectTimeout(cc, timeout);
valkeyClusterSetOptionRouteUseSlots(cc);
valkeyClusterConnect2(cc);
if (!cc) {
printf("Error: Allocation failure\n");
exit(-1);
} else if (cc->err) {
printf("Error: %s\n", cc->errstr);
// handle error
exit(-1);
}
valkeyReply *reply = valkeyClusterCommand(cc, "SET %s %s", "key", "value");
printf("SET: %s\n", reply->str);
freeReplyObject(reply);
valkeyReply *reply2 = valkeyClusterCommand(cc, "GET %s", "key");
printf("GET: %s\n", reply2->str);
freeReplyObject(reply2);
valkeyClusterFree(cc);
return 0;
}