Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127//! Redis client for Zig//!//! A minimal Redis client implementing RESP (REdis Serialization Protocol).//! Supports strings, hashes, lists, sets, sorted sets, and streams.//!//! ## Design Philosophy//!//! - **Tagged unions for RESP values**: `Value = union(enum)` represents all Redis types//! - **Distinct error sets**: Network/protocol/command errors are categorized//! - **Buffer ownership**: Client owns read buffer; returned slices valid until next command//! - **Modular commands**: Each data type has its own command module//!//! ## Quick Start//!//! ```zig//! const redis = @import("redis");//!//! var client = try redis.Client.connect(allocator, "localhost", 6379);//! defer client.close();//!//! // String operations//! var str = client.strings();//! try str.set("key", "value");//! const val = try str.get("key");//!//! // Stream operations//! var streams = client.streams();//! const id = try streams.xadd("events", .auto, &.{.{"type", "login"}});//! ```//!//! ## Module Structure//!//! - `resp.zig`: RESP protocol types, parsing, error definitions//! - `client.zig`: Connection management, buffer handling, command execution//! - `commands/`: Data structure-specific command implementations//! - `strings.zig`: String operations (GET, SET, INCR, etc.)//! - `keys.zig`: Generic key operations (DEL, EXPIRE, TTL, etc.)//! - `hashes.zig`: Hash operations (HSET, HGET, HGETALL, etc.)//! - `lists.zig`: List operations (LPUSH, RPOP, LRANGE, etc.)//! - `sets.zig`: Set operations (SADD, SREM, SMEMBERS, etc.)//! - `sorted_sets.zig`: Sorted set operations (ZADD, ZRANGE, etc.)//! - `streams.zig`: Stream operations (XADD, XREAD, XREADGROUP, etc.)
const std = @import("std");
// ============================================================================// Core Types (re-exported from resp.zig)// ============================================================================
pub const resp = @import("resp.zig");
/// RESP value type - tagged union representing all Redis return typespub const Value = resp.Value;
/// Errors during connection (network, auth)pub const ConnectionError = resp.ConnectionError;
/// Errors in RESP parsing (malformed response)pub const ProtocolError = resp.ProtocolError;
/// Errors from Redis commands (WRONGTYPE, etc.)pub const CommandError = resp.CommandError;
/// Combined error set for all client operationspub const ClientError = resp.ClientError;
/// RESP protocol parserpub const Parser = resp.Parser;
/// RESP command builderpub const CommandBuilder = resp.CommandBuilder;
// ============================================================================// Client (re-exported from client.zig)// ============================================================================
pub const client_mod = @import("client.zig");
/// Redis client with connection and buffer managementpub const Client = client_mod.Client;
// ============================================================================// Command Modules// ============================================================================
pub const strings = @import("commands/strings.zig");pub const keys = @import("commands/keys.zig");pub const hashes = @import("commands/hashes.zig");pub const lists = @import("commands/lists.zig");pub const sets = @import("commands/sets.zig");pub const sorted_sets = @import("commands/sorted_sets.zig");pub const streams = @import("commands/streams.zig");
// ============================================================================// Stream Types (commonly used, re-exported for convenience)// ============================================================================
/// A field-value pair in a stream entrypub const StreamField = streams.StreamField;
/// A single entry from a Redis streampub const StreamEntry = streams.StreamEntry;
/// Result from XAUTOCLAIM commandpub const AutoclaimResult = streams.AutoclaimResult;
/// Stream ID for XADDpub const StreamId = streams.StreamId;
// ============================================================================// Tests// ============================================================================
test { // Run tests from all submodules std.testing.refAllDecls(@This()); _ = resp; _ = client_mod; _ = strings; _ = keys; _ = hashes; _ = lists; _ = sets; _ = sorted_sets; _ = streams;}