Skip to content

Instantly share code, notes, and snippets.

@kristoff-it
Created April 29, 2020 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristoff-it/4ace19ed0a57ce7c0be806e33d5664b1 to your computer and use it in GitHub Desktop.
Save kristoff-it/4ace19ed0a57ce7c0be806e33d5664b1 to your computer and use it in GitHub Desktop.
const std = @import("std");
const time = std.time;
const builtin = @import("builtin");
const heyredis = @import("./src/okredis.zig");
pub const io_mode = .evented;
const addr = if (builtin.os.tag == .linux) "192.168.65.2" else "127.0.0.1";
pub fn main() !void {
var client: heyredis.Client = undefined;
try heyredis.Client.initIp4(&client, addr, 6379);
defer client.close();
try client.send(void, .{ "SET", "counter", "0" });
const cmd = .{ "INCR", "counter" };
var i: usize = 0;
const loops: usize = 1000;
comptime var FrameType = @TypeOf(async client.send(void, cmd));
var frames: [loops]FrameType = undefined;
var t = try time.Timer.start();
for (frames) |*f| {
f.* = async client.send(void, cmd);
}
for (frames) |*f| {
try await f;
}
var took = t.read();
std.debug.warn("Counter INCR -- OK [{d}ms]\n\n", .{@intToFloat(f64, took) / time.millisecond});
std.debug.warn("Final value: [{}]\n\n", .{try client.send(i64, .{ "GET", "counter" })});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment