$ show valkey-io/valkey
Valkey is a high-performance in-memory data structure server, forked from Redis under a BSD-3-Clause license. It serves as a key-value store with support for strings, hashes, lists, sets, sorted sets, streams, geospatial indexes, and more. The architecture is event-loop-driven (single-threaded main loop with background I/O threads for persistence, replication, and lazy freeing). It supports clustering (up to 16384 slots), replication (leader-follower with partial resync), persistence (RDB snapshots, AOF logs), Lua scripting (EVAL/FUNCTION), a pluggable module API, TLS, RDMA, and advanced features like client-side caching, hot-key detection, and replication throttling. Key entry points include the `valkey-server` daemon, `valkey-cli` client, `valkey-benchmark` load generator, and `valkey-check-rdb`/`valkey-check-aof` integrity tools. External dependencies include jemalloc (default allocator), Lua 5.1, LZ4, Zstd (optional), OpenSSL (TLS), and RDMA libraries (optional). The codebase is actively maintained with extensive unit and integration tests, and demonstrates high craftsmanship in its lock-free queues, streaming compression, and data structure implementations.
The LLM identified 6 files worth highlighting for reuse:
Implements multiple lock-free queue variants (MPSC, SPMC, SPSC) using cache-line-padded head/tail pointers, sequence numbers, and ticket-based reservation. Provides batch enqueue/dequeue and is used internally for inter-thread communication (e.g., bio, io-threads). The design is self-contained and can be extracted for any high-performance producer-consumer pattern.
Defines a streaming compression abstraction with a VCS envelope (magic, version, codec type, stream kind) and push/pull reader interfaces. Supports LZ4 and Zstd codecs with frame flushing, checksums, and passthrough for uncompressed data. The pattern is reusable for any application needing pluggable streaming compression.
Provides a polymorphic I/O abstraction (rio) with vtbl-like static structs for file, socket, buffer, and connection backends. Supports read, write, tell, flush, checksum updates, and attachable stream compression. The design is clean and can be reused in any C project requiring abstract I/O.
A modern hash table implementation designed for cache-friendliness and incremental rehashing. Replaces the legacy dict with batch operations, improved memory layout, and better performance under high load. The API is self-contained and can be extracted for use in other C projects.
Implements the Space-Saving algorithm for tracking top-K frequent items over a sliding window. Supports configurable window size, sampling percentage, and frozen-window rotation. Used for hot-key detection. The algorithm is well-documented and can be reused in any streaming frequency estimation context.
Provides a monotonic clock abstraction with hardware-specific implementations (x86 TSC, ARM cycle counter, POSIX clock_gettime) and fallback. Uses a global function pointer for fast dispatch and includes calibration logic. The pattern is reusable for any C project needing precise, portable timing.