FastKey is a Redis clone implementation written in C that supports core Redis functionality including key-value storage, replication, streams, transactions, and concurrent client handling.
- Redis Protocol Compatibility: Implements Redis Serialization Protocol (RESP)
- Core Commands: SET, GET, DEL, PING, ECHO, CONFIG, INFO, KEYS, TYPE, XADD, XRANGE, XREAD
- Replication: Master-slave replication with PSYNC, REPLCONF commands
- Transactions: MULTI, EXEC, DISCARD support
- Streams: Redis streams with XADD, XRANGE, XREAD operations
- Concurrency: Thread pool for handling multiple client connections
- Persistence: RDB file format support
- Expiration: TTL support for keys
- Logging: Comprehensive logging system
- C Compiler: GCC or compatible C compiler
- POSIX Threads: pthread library for threading support
- Standard C Libraries: stdlib, string, time, etc.
# Clone the repository
git clone https://github.com/botirk38/fastkey.git
cd fastkey
# Build using the provided script
./your_program.sh
# Or build manually
gcc -o fastkey app/*.c -lpthread
# Start the server (default port 6379)
./fastkey
# Start with custom configuration
./fastkey --port 8080 --dir /tmp --dbfilename dump.rdb
# Start as replica
./fastkey --replicaof localhost 6379
Connect using any Redis client (redis-cli, telnet, etc.):
redis-cli -p 6379
- String Operations: SET, GET, DEL
- Server: PING, ECHO, CONFIG GET, INFO
- Keys: KEYS, TYPE, EXPIRE
- Replication: PSYNC, REPLCONF
- Transactions: MULTI, EXEC, DISCARD
- Streams: XADD, XRANGE, XREAD
- Blocking: WAIT (master-replica synchronization)
- Server: Main server loop and connection handling
- Client Handler: Per-client connection management
- Command Parser: RESP protocol parsing and command execution
- Redis Store: In-memory key-value storage with thread safety
- Replication: Master-slave replication logic
- Streams: Redis streams implementation
- Thread Pool: Concurrent client handling
- Logger: Structured logging system
The implementation uses read-write locks to ensure thread-safe access to the shared data store while allowing concurrent reads.
--port
: Server port (default: 6379)--dir
: Working directory for RDB files--dbfilename
: RDB filename--replicaof
: Configure as replica of specified master
Logging level can be configured via the logger initialization in main.c.
This project includes a comprehensive test suite covering all core functionality:
# Build and run all tests
make test
# Build the main application
make
# Clean build artifacts
make clean
Test Coverage:
- Redis Store Module: Key-value operations, expiry handling, type checking
- RESP Protocol: Buffer management, string encoding, array parsing
- Command Execution: PING, ECHO, SET, GET, TYPE commands
- Stream Operations: Stream creation, entry management, range queries
- Integration Tests: Server initialization, networking, concurrency
Test Results:
- 256 total tests with 100% pass rate
- Memory leak detection and proper cleanup validation
- Thread-safe operation testing
The codebase follows these principles:
- Memory safety with proper cleanup
- Thread safety for concurrent access
- Error handling and logging
- Modular design with clear separation of concerns
This project is for educational purposes and open source development.