-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.zig
More file actions
50 lines (33 loc) · 1.41 KB
/
Copy pathmain.zig
File metadata and controls
50 lines (33 loc) · 1.41 KB
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
const lib = @import("dizeDB");
const std = @import("std");
const print = std.debug.print;
const Command = lib.Command;
const ResultReader = lib.ResultReader;
pub fn main() !void {
var gpa = std.heap.DebugAllocator(.{}){};
const allocator = gpa.allocator();
var client = try lib.Client.newConn(allocator, "127.0.0.1", 7379, .{ .retry = 3 });
defer client.deinit();
{
const args1: ?[]const ?[]const u8 = &.{ "HELLO", "THIS IS A TEST" };
const result1: ResultReader = client.fire(.{ .cmd = Command{ .cmd = "SET", .args = args1 } });
defer result1.deinit();
print("SET: {any} {?s}\n", .{ result1.getStatus(), result1.getMessage() });
}
{
const args2: ?[]const ?[]const u8 = &.{"HELLO"};
const result2: ResultReader = client.fire(.{ .cmd = Command{ .cmd = "GET", .args = args2 } });
defer result2.deinit();
const data = try result2.getGETRes(allocator);
defer data.deinit();
print("GET: {any} {s}\n", .{ result2.getStatus(), data.getValue() });
}
{
const result3 = client.fire(.{.str = "SET HI 7"});
defer result3.deinit();
print("SET: {any} {s}\n", .{ result3.getStatus(), result3.getMessage() });
}
const result4 = client.fire(.{.str = "GET HI"});
const data2 = try result4.getGETRes(allocator);
print("GET: {any} {s}\n", .{ result4.getStatus(), data2.getValue() });
}