Pedis
A sleek, Golang-powered learning adventure inspired by Redis
What is Pedis?
Pedis is a Redis clone written in Golang. It is a learning project for me to learn Redis protocol. It is not intended to be a production-ready Redis clone.
Build
Pedis does not have any external dependencies. To build it, simply run:
$ go build -o pedis-server && ./pedis-server
Usage
- Initialize a Pedis server
package main
import (
"ahmedash95/pedis/pedis"
"fmt"
)
func main() {
fmt.Println("Listening on port 6379")
config := &pedis.Config{
EnableAof: true,
} // to enable AOF persistence or set config to nil
server := pedis.NewServer(config)
server.ListenAndServe("0.0.0.0:6379")
}
- Connect to the server using a Redis client
$ redis-cli -p 6379
Supported Commands
- GET
- SET
- DEL
- EXISTS
- EXPIRE
- TTL
- HSET
- HGET
- HGETALL
- HDEL
- HLEN
- HKEYS
- HVALS
Persistence
At the moment, Pedis supports AOF persistence. It is disable by default. To enabled it, set EnableAof
to true
in the config. the policy for now is to append to the AOF file every second.
Benchmarks
With no disk persistence
go run main.go
$ redis-benchmark -p 6379 -n 100000 -c 100 -t set,get
SET: 411761.19 requests per second
GET: 476640.00 requests per second
License
MIT
Persisting records to disk by implementing aof
Implemented (Append only file) that logs every write operation received by the server. these operations will be replayed again on server startup. commands are logged using the same format as the Redis protocol itself.
Also there is a new config struct to make it easy to enable/disable AOF on server startup
Persist to desk
We want to add a persistent layer feature to Pedis to ensure that data is not lost in case of a system failure or other issue. We are considering using either the Append-Only File (AOF) or Redis Database Backup (RDB) mechanism to implement this feature.
The AOF mechanism logs every write operation to a file on disk in a compact, human-readable format. The RDB mechanism takes a point-in-time snapshot of the Redis database and writes it to disk as a binary file.
Tasks:
Support Expiration of Keys
We want to add support for key expiration to Pedis to automatically delete keys after a specified period of time. This will help us manage memory usage and ensure that stale data is not retained indefinitely.
Tasks: