-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathcluster-simple.c
More file actions
33 lines (26 loc) · 862 Bytes
/
cluster-simple.c
File metadata and controls
33 lines (26 loc) · 862 Bytes
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
#include <valkey/cluster.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
struct timeval timeout = {1, 500000}; // 1.5s
valkeyClusterOptions options = {0};
options.initial_nodes = "127.0.0.1:7000";
options.connect_timeout = &timeout;
valkeyClusterContext *cc = valkeyClusterConnectWithOptions(&options);
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;
}