barddoo/zedis
Redis in Zig
A Redis-compatible in-memory data store written in Zig, designed for learning and experimentation. Zedis implements the core Redis protocol and data structures with a focus on simplicity, performance, and thread safety.
# Clone the repository
git clone https://github.com/barddoo/zedis.git
cd zedis
# Build the project
zig build
# Run the server
zig build run
The server will start on 127.0.0.1:6379
by default.
You can test Zedis using the standard redis-cli
or any Redis client:
# Connect to Zedis
redis-cli -h 127.0.0.1 -p 6379
# Try some commands
127.0.0.1:6379> SET mykey "Hello, Zedis!"
OK
127.0.0.1:6379> GET mykey
"Hello, Zedis!"
127.0.0.1:6379> INCR counter
(integer) 1
127.0.0.1:6379> TYPE mykey
string
SET key value
- Set a key to hold a string valueGET key
- Get the value of a keyINCR key
- Increment the integer value of a key by oneDECR key
- Decrement the integer value of a key by oneINCRBY key increment
- Increment the integer value of a key by the given amountDECRBY key decrement
- Decrement the integer value of a key by the given amountDEL key [key ...]
- Delete one or more keysEXISTS key [key ...]
- Check if keys existTYPE key
- Determine the type stored at keyPING [message]
- Ping the serverECHO message
- Echo the given stringZedis is built with a modular architecture:
src/
βββ main.zig # Entry point and server initialization
βββ server.zig # TCP server and connection handling
βββ client.zig # Client connection management
βββ store.zig # Thread-safe in-memory data store
βββ parser.zig # RESP protocol parser
βββ commands/ # Command implementations
βββ registry.zig # Command registration and dispatch
βββ t_string.zig # String type commands
βββ connection.zig # Connection commands
Zedis is designed for high performance:
The codebase follows Zig conventions with clear separation of concerns:
# Build in debug mode (default)
zig build -Doptimize=Debug
# Build optimized release
zig build -Doptimize=ReleaseFast
# Run tests (when available)
zig build test
src/commands/
Example:
pub fn myCommand(client: *Client, args: []const Value) !void {
// Command implementation
try client.writeSimpleString("OK");
}
Current limitations (contributions welcome!):
Add persistence (RDB snapshots)
Implement more Redis commands
Add support for lists and sets
Implement pub/sub functionality
Add configuration file support
Implement key expiration
Add clustering support
Performance benchmarking suite
Contributions are welcome! Here's how you can help:
git checkout -b feature/amazing-feature
git commit -m 'Add amazing feature'
git push origin feature/amazing-feature
zig fmt
)This project is licensed under the MIT License - see the LICENSE file for details.
Zedis - Learning Redis internals through Zig! π¦β‘