{"id":13711934,"url":"https://github.com/kristoff-it/zig-okredis","last_synced_at":"2025-04-06T14:10:14.627Z","repository":{"id":45981445,"uuid":"203636721","full_name":"kristoff-it/zig-okredis","owner":"kristoff-it","description":"Zero-allocation Client for all the various Redis forks","archived":false,"fork":false,"pushed_at":"2025-03-30T10:10:55.000Z","size":1531,"stargazers_count":232,"open_issues_count":1,"forks_count":19,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-30T13:07:39.051Z","etag":null,"topics":["okredis","redis","redis-client","zero-allocation","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristoff-it.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-21T17:53:43.000Z","updated_at":"2025-03-30T10:10:58.000Z","dependencies_parsed_at":"2024-03-30T22:01:16.736Z","dependency_job_id":null,"html_url":"https://github.com/kristoff-it/zig-okredis","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoff-it%2Fzig-okredis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoff-it%2Fzig-okredis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoff-it%2Fzig-okredis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristoff-it%2Fzig-okredis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristoff-it","download_url":"https://codeload.github.com/kristoff-it/zig-okredis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492513,"owners_count":20947544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["okredis","redis","redis-client","zero-allocation","zig"],"created_at":"2024-08-02T23:01:13.086Z","updated_at":"2025-04-06T14:10:14.607Z","avatar_url":"https://github.com/kristoff-it.png","language":"Zig","funding_links":[],"categories":["Zig","Database","Applications","Data \u0026 Science"],"sub_categories":["Database"],"readme":"\n\u003ch1 align=\"center\"\u003eOkRedis\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://badgen.net/github/license/kristoff-it/zig-okredis\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://twitter.com/croloris\"\u003e\u003cimg src=\"https://badgen.net/badge/twitter/@croloris/1DA1F2?icon\u0026label\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    OkRedis is a zero-allocation client for Redis 6+\n\u003c/p\u003e\n\n## Handy and Efficient\nOkRedis aims to offer an interface with great ergonomics without\ncompromising on performance or flexibility.\n\n## Project status\nOkRedis is currently in alpha. The main features are mostly complete,\nbut a lot of polishing is still required. Zig version `0.14.0` is\nsupported.\n\nEverything mentioned in the docs is already implemented and you can just\n`zig run example.zig` to quickly see what it can do. Remember OkRedis only\nsupports Redis 6 and above.\n\n## Zero dynamic allocations, unless explicitly wanted\nThe client has two main interfaces to send commands: `send` and `sendAlloc`.\nFollowing Zig's mantra of making dynamic allocations explicit, only `sendAlloc`\ncan allocate dynamic memory, and only does so by using a user-provided allocator.\n\nThe way this is achieved is by making good use of RESP3's typed responses and\nZig's metaprogramming facilities.\nThe library uses compile-time reflection to specialize down to the parser level,\nallowing OkRedis to decode whenever possible a reply directly into a function\nframe, **without any intermediate dynamic allocation**. If you want more\ninformation about Zig's comptime:\n- [Official documentation](https://ziglang.org/documentation/master/#comptime)\n- [What is Zig's Comptime?](https://kristoff.it/blog/what-is-zig-comptime) (blog post written by me)\n\nBy using `sendAlloc` you can decode replies with arbrirary shape at the cost of\noccasionally performing dynamic allocations. The interface takes an allocator\nas input, so the user can setup custom allocation schemes such as\n[arenas](https://en.wikipedia.org/wiki/Region-based_memory_management).\n\n## Quickstart\n\n```zig\nconst std = @import(\"std\");\nconst okredis = @import(\"./src/okredis.zig\");\nconst SET = okredis.commands.strings.SET;\nconst OrErr = okredis.types.OrErr;\nconst Client = okredis.Client;\n\npub fn main() !void {\n    const addr = try std.net.Address.parseIp4(\"127.0.0.1\", 6379);\n    var connection = try std.net.tcpConnectToAddress(addr);\n\n    var client: Client = undefined;\n    try client.init(connection);\n    defer client.close();\n\n    // Basic interface\n    try client.send(void, .{ \"SET\", \"key\", \"42\" });\n    const reply = try client.send(i64, .{ \"GET\", \"key\" });\n    if (reply != 42) @panic(\"out of towels\");\n\n\n    // Command builder interface\n    const cmd = SET.init(\"key\", \"43\", .NoExpire, .IfAlreadyExisting);\n    const otherReply = try client.send(OrErr(void), cmd);\n    switch (otherReply) {\n        .Nil =\u003e @panic(\"command should not have returned nil\"),\n        .Err =\u003e @panic(\"command should not have returned an error\"),\n        .Ok =\u003e std.debug.print(\"success!\", .{}),\n    }\n}\n```\n\n## Available Documentation\nThe reference documentation [is available here](https://kristoff.it/zig-okredis#root).\n\n   * [Using the OkRedis client](CLIENT.md#using-the-okredis-client)\n      * [Connecting](CLIENT.md#connecting)\n      * [Buffering](CLIENT.md#buffering)\n      * [Evented vs blocking I/O](CLIENT.md#evented-vs-blocking-io)\n      * [Pipelining](CLIENT.md#pipelining)\n      * [Transactions](CLIENT.md#transactions)\n      * [Pub/Sub](CLIENT.md#pubsub)\n\n   * [Sending commands](COMMANDS.md#sending-commands)\n      * [Base interface](COMMANDS.md#base-interface)\n      * [Command builder interface](COMMANDS.md#command-builder-interface)\n      * [Validating command syntax](COMMANDS.md#validating-command-syntax)\n      * [Optimized command builders](COMMANDS.md#optimized-command-builders)\n      * [Creating new command builders](COMMANDS.md#creating-new-command-builders)\n      * [An afterword on command builders vs methods](COMMANDS.md#an-afterword-on-command-builders-vs-methods)\n\n   * [Decoding Redis Replies](REPLIES.md#decoding-redis-replies)\n      * [Introduction](REPLIES.md#introduction)\n      * [The first and second rule of decoding replies](REPLIES.md#the-first-and-second-rule-of-decoding-replies)\n      * [Decoding Zig types](REPLIES.md#decoding-zig-types)\n         * [Void](REPLIES.md#void)\n         * [Numbers](REPLIES.md#numbers)\n         * [Optionals](REPLIES.md#optionals)\n         * [Strings](REPLIES.md#strings)\n         * [Structs](REPLIES.md#structs)\n      * [Decoding Redis errors and nil replies as values](REPLIES.md#decoding-redis-errors-and-nil-replies-as-values)\n         * [Redis OK replies](REPLIES.md#redis-ok-replies)\n      * [Allocating memory dynamically](REPLIES.md#allocating-memory-dynamically)\n         * [Allocating strings](REPLIES.md#allocating-strings)\n         * [Freeing complex replies](REPLIES.md#freeing-complex-replies)\n         * [Allocating Redis Error messages](REPLIES.md#allocating-redis-error-messages)\n         * [Allocating structured types](REPLIES.md#allocating-structured-types)\n      * [Parsing dynamic replies](REPLIES.md#parsing-dynamic-replies)\n      * [Bundled types](REPLIES.md#bundled-types)\n      * [Decoding types in the standard library](REPLIES.md#decoding-types-in-the-standard-library)\n      * [Implementing decodable types](REPLIES.md#implementing-decodable-types)\n         * [Adding types for custom commands (Lua scripts or Redis modules)](REPLIES.md#adding-types-for-custom-commands-lua-scripts-or-redis-modules)\n         * [Adding types used by a higher-level language](REPLIES.md#adding-types-used-by-a-higher-level-language)\n\n## Extending OkRedis\nIf you are a Lua script or Redis module author, you might be interested in\nreading the final sections of `COMMANDS.md` and `REPLIES.md`.\n\n## Embedding OkRedis in a higher level language\nTake a look at the final section of `REPLIES.md`.\n\n## TODOS\n- Implement remaining command builders\n- Better connection management (ipv6, unixsockets, ...)\n- Streamline design of Zig errors\n- Refine support for async/await and think about connection pooling\n- Refine the Redis traits\n- Pub/Sub\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristoff-it%2Fzig-okredis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristoff-it%2Fzig-okredis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristoff-it%2Fzig-okredis/lists"}