$ show nalgeon/redka
Redka is a Redis-compatible data store implemented in Go, using SQLite or PostgreSQL as the storage backend. It reimplements core Redis data structures (strings, lists, sets, hashes, sorted sets) with full TTL support, key scanning, and set/sorted-set aggregation operations. The system can be deployed either as an embedded Go library (via the `redka` module) or as a standalone RESP-compatible server (single binary or Docker image). Architecture follows a clean layered design: a top-level `DB` struct provides transactional access to per-type repositories (e.g., `ZSet()`, `Hash()`), which in turn use a dialect abstraction layer (`sqlx`) to generate SQLite- or PostgreSQL-specific queries. The RESP server is built on `tidwall/redcon` with a command dispatch pattern and a reusable parser combinator framework for argument parsing. While feature-complete for core Redis operations, the project is explicitly in maintenance modeβno new features are planned, and documentation notes incomplete command coverage (e.g., blocking operations, some sorted set commands). The codebase is well-structured with extensive test coverage, but Postgres support shows signs of drift (many queries aliased to SQLite) and the command dispatch switch has grown large.
The LLM identified 4 files worth highlighting for reuse:
Implements a functional parser combinator framework for Redis command arguments. Provides composable parsers like `String`, `Int`, `Float`, `Enum`, `Flag`, `Named`, `OneOf`, and `Pipeline`. Each parser is a pure function that consumes tokens and returns the remaining tokens plus a result. This pattern eliminates manual tokenization and error handling across 70+ Redis commands, and can be extracted for any protocol that requires strict argument parsing with positional and optional parameters.
Provides a generic `Transactor` interface and its implementation that wraps `database/sql` connections. Exposes `View` (read-only) and `Update` (read-write) methods that accept a function operating on a `sqlx.Tx`. Each method handles transaction lifecycle (begin, commit/rollback) and respects a configurable context timeout. This abstraction is cleanly separated from dialect specifics and can be reused in any Go application requiring transactional database access with timeout support.
Implements a paginated scanner for iterating over keys in the `rkey` table using a cursor based on `rowid`. Provides a `Scanner` struct with `Scan` (returns a batch of keys) and `Next` (iterator) methods. Handles expired key filtering and supports prefix and glob pattern matching. The pattern is replicated across other data types (rhash, rset, rzset) and demonstrates a clean, reusable approach for chunked database iteration without loading all results into memory.
Defines a `RangeWith` builder for constructing complex sorted set range queries (by rank or by score, with direction, offset, count, and score exclusion). The fluent interface returns a `RangeCmd` that is executed via `Run()`. This decouples query construction from execution and allows the same builder to be reused for `ZRange`, `ZRangeByScore`, `ZRevRange`, etc. The pattern is also used in `delete.go` and could be extracted for any domain requiring composable query filters.