https://github.com/botirk38/fastkey
A high-performance key-value store built with C, utilizing a thread pool for concurrency and the RESP protocol for communication.
https://github.com/botirk38/fastkey
Last synced: 5 months ago
JSON representation
A high-performance key-value store built with C, utilizing a thread pool for concurrency and the RESP protocol for communication.
- Host: GitHub
- URL: https://github.com/botirk38/fastkey
- Owner: botirk38
- Created: 2025-01-20T17:04:24.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2025-07-03T13:48:12.000Z (5 months ago)
- Last Synced: 2025-07-03T14:50:38.411Z (5 months ago)
- Language: C
- Homepage:
- Size: 348 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastKey - Redis Clone
## Project Overview
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.
### Key Features
- **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
## Getting Started
### Prerequisites
- **C Compiler**: GCC or compatible C compiler
- **POSIX Threads**: pthread library for threading support
- **Standard C Libraries**: stdlib, string, time, etc.
### Building
```bash
# 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
```
### Running
```bash
# 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
```
## Usage
### Connecting
Connect using any Redis client (redis-cli, telnet, etc.):
```bash
redis-cli -p 6379
```
### Supported Commands
- **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)
## Architecture
### Core Components
- **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
### Thread Safety
The implementation uses read-write locks to ensure thread-safe access to the shared data store while allowing concurrent reads.
## Configuration
### Command Line Options
- `--port`: Server port (default: 6379)
- `--dir`: Working directory for RDB files
- `--dbfilename`: RDB filename
- `--replicaof`: Configure as replica of specified master
### Environment
Logging level can be configured via the logger initialization in main.c.
## Development
### Testing
This project includes a comprehensive test suite covering all core functionality:
```bash
# 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
### Code Quality
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
## License
This project is for educational purposes and open source development.