Gored is a high-performance, in-memory key-value store designed for low-latency, high-throughput workloads. It follows the RESP (Redis Serialization Protocol) and provides a minimal yet efficient caching solution with a built-in LRU eviction strategy.
- Optimized for high request throughput with minimal latency
- Uses an in-memory storage engine with an LRU eviction policy
- Implements RESP for seamless Redis compatibility
- Multi-threaded architecture with sharded cache design
- Efficient memory management to fit within limited RAM constraints
- Deployable as a standalone binary or in a Docker container
- Sharded LRU Cache: Cache is divided into multiple shards to reduce lock contention and improve concurrency.
- Efficient Hashing: Uses FNV-1a hashing for distributing keys across shards.
- Optimized Data Structures: Uses a combination of hash maps and doubly linked lists to achieve O(1) lookups and O(1) evictions.
- Memory-Conscious: Carefully managed memory to prevent unnecessary allocations and reduce garbage collection overhead.
- Direct RESP Protocol: Eliminates HTTP overhead by using the RESP protocol directly over TCP.
- Connection Reuse: Supports persistent client connections for better performance.
- Read-Write Optimization: Uses fine-grained locking to allow concurrent reads while limiting write contention.
- Buffer Pooling: Reduces memory allocations by reusing buffers.
- Automatic CPU Scaling: Uses all available CPU cores for better efficiency.
To quickly run Gored using Docker, follow these steps:
# Pull the latest Gored image from Docker Hub
docker pull your-dockerhub-username/gored:latest
# Run the container
docker run -p 7171:7171 your-dockerhub-username/gored:latestIf you prefer to run Gored without Docker, you can build and run it manually:
# Clone the repository
git clone https://github.com/your-repo/gored.git && cd gored
# Initialize Go modules
go mod init gored
# Download dependencies
go mod tidy
# Build the binary
go build -o gored
# Start the server
./goredGored communicates over TCP using the RESP protocol, making it compatible with Redis clients.
SET key value- Stores a key-value pairGET key- Retrieves the value of a given keyPING- Returns a PONG response to test connectivitySTATS- Returns cache statistics
If you have Redis installed, you can use the Redis CLI to interact with Gored:
redis-cli -p 7171
SET mykey "Hello, World!"
GET mykeyYou can also send raw RESP commands manually:
# Send a SET command
printf "*3\r\n$3\r\nSET\r\n$5\r\nmykey\r\n$13\r\nHello, World!\r\n" | nc localhost 7171
# Send a GET command
printf "*2\r\n$3\r\nGET\r\n$5\r\nmykey\r\n" | nc localhost 7171The following table summarizes the performance of the Redis-like cache under a high-concurrency workload using redis-benchmark.
| Operation | Requests | Time Taken (s) | Clients | Avg Latency (ms) | P50 Latency (ms) | P95 Latency (ms) | P99 Latency (ms) | Max Latency (ms) | Throughput (req/sec) |
|---|---|---|---|---|---|---|---|---|---|
| SET | 1,000,000 | 15.98 | 10,000 | 79.174 | 78.655 | 104.703 | 113.151 | 161.535 | 62,566.48 |
| GET | 1,000,000 | 15.94 | 10,000 | 79.167 | 79.167 | 100.159 | 112.639 | 130.239 | 62,801.51 |
- Benchmark was executed using
redis-benchmark -t SET,GET -n 1000000 -c 10000. - Latency metrics represent the time taken per request.
- Throughput is the number of requests served per second.
You can use Locust to benchmark Gored's performance.
pip install locust
locust -f locustfile.py --host=tcp://localhost:7171Then open http://localhost:8089 in a web browser to start the test.
Benchmarking on an AWS t3.small instance (2 vCPUs, 2GB RAM) shows:
- Over 11,000 requests per second
- Average latency under 5ms
- 0% cache miss rate for actively used keys
- Memory usage remains within safe limits under high load
- If a key does not exist, the server returns a null bulk string (
$-1\r\n). - If the cache exceeds its memory limit, the LRU eviction policy removes the least recently used keys.
- Errors are returned in RESP format and follow Redis-like conventions.
- The server handles client disconnections and network errors gracefully.
If you'd like to contribute to Gored, feel free to submit pull requests or report issues on the GitHub repository.
Gored is open-source and released under the MIT License.