this repo has no description
1//! Redis client for Zig
2//!
3//! A minimal Redis client implementing RESP (REdis Serialization Protocol).
4//! Supports strings, hashes, lists, sets, sorted sets, and streams.
5//!
6//! ## Design Philosophy
7//!
8//! - **Tagged unions for RESP values**: `Value = union(enum)` represents all Redis types
9//! - **Distinct error sets**: Network/protocol/command errors are categorized
10//! - **Buffer ownership**: Client owns read buffer; returned slices valid until next command
11//! - **Modular commands**: Each data type has its own command module
12//!
13//! ## Quick Start
14//!
15//! ```zig
16//! const redis = @import("redis");
17//!
18//! var client = try redis.Client.connect(allocator, "localhost", 6379);
19//! defer client.close();
20//!
21//! // String operations
22//! var str = client.strings();
23//! try str.set("key", "value");
24//! const val = try str.get("key");
25//!
26//! // Stream operations
27//! var streams = client.streams();
28//! const id = try streams.xadd("events", .auto, &.{.{"type", "login"}});
29//! ```
30//!
31//! ## Module Structure
32//!
33//! - `resp.zig`: RESP protocol types, parsing, error definitions
34//! - `client.zig`: Connection management, buffer handling, command execution
35//! - `commands/`: Data structure-specific command implementations
36//! - `strings.zig`: String operations (GET, SET, INCR, etc.)
37//! - `keys.zig`: Generic key operations (DEL, EXPIRE, TTL, etc.)
38//! - `hashes.zig`: Hash operations (HSET, HGET, HGETALL, etc.)
39//! - `lists.zig`: List operations (LPUSH, RPOP, LRANGE, etc.)
40//! - `sets.zig`: Set operations (SADD, SREM, SMEMBERS, etc.)
41//! - `sorted_sets.zig`: Sorted set operations (ZADD, ZRANGE, etc.)
42//! - `streams.zig`: Stream operations (XADD, XREAD, XREADGROUP, etc.)
43
44const std = @import("std");
45
46// ============================================================================
47// Core Types (re-exported from resp.zig)
48// ============================================================================
49
50pub const resp = @import("resp.zig");
51
52/// RESP value type - tagged union representing all Redis return types
53pub const Value = resp.Value;
54
55/// Errors during connection (network, auth)
56pub const ConnectionError = resp.ConnectionError;
57
58/// Errors in RESP parsing (malformed response)
59pub const ProtocolError = resp.ProtocolError;
60
61/// Errors from Redis commands (WRONGTYPE, etc.)
62pub const CommandError = resp.CommandError;
63
64/// Combined error set for all client operations
65pub const ClientError = resp.ClientError;
66
67/// RESP protocol parser
68pub const Parser = resp.Parser;
69
70/// RESP command builder
71pub const CommandBuilder = resp.CommandBuilder;
72
73// ============================================================================
74// Client (re-exported from client.zig)
75// ============================================================================
76
77pub const client_mod = @import("client.zig");
78
79/// Redis client with connection and buffer management
80pub const Client = client_mod.Client;
81
82// ============================================================================
83// Command Modules
84// ============================================================================
85
86pub const strings = @import("commands/strings.zig");
87pub const keys = @import("commands/keys.zig");
88pub const hashes = @import("commands/hashes.zig");
89pub const lists = @import("commands/lists.zig");
90pub const sets = @import("commands/sets.zig");
91pub const sorted_sets = @import("commands/sorted_sets.zig");
92pub const streams = @import("commands/streams.zig");
93
94// ============================================================================
95// Stream Types (commonly used, re-exported for convenience)
96// ============================================================================
97
98/// A field-value pair in a stream entry
99pub const StreamField = streams.StreamField;
100
101/// A single entry from a Redis stream
102pub const StreamEntry = streams.StreamEntry;
103
104/// Result from XAUTOCLAIM command
105pub const AutoclaimResult = streams.AutoclaimResult;
106
107/// Stream ID for XADD
108pub const StreamId = streams.StreamId;
109
110// ============================================================================
111// Tests
112// ============================================================================
113
114test {
115 // Run tests from all submodules
116 std.testing.refAllDecls(@This());
117 _ = resp;
118 _ = client_mod;
119 _ = strings;
120 _ = keys;
121 _ = hashes;
122 _ = lists;
123 _ = sets;
124 _ = sorted_sets;
125 _ = streams;
126}