A sleek, Golang-powered learning adventure inspired by Redis

  • By Ahmed Ammar
  • Last update: Aug 10, 2023
  • Comments: 3


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.


Pedis does not have any external dependencies. To build it, simply run:

$ go build -o pedis-server && ./pedis-server


  • Initialize a Pedis server
package main

import (

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)
  • Connect to the server using a Redis client
$ redis-cli -p 6379

Supported Commands

  • GET
  • SET
  • DEL
  • TTL
  • HSET
  • HGET
  • HDEL
  • HLEN


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.


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






  • 1

    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

    func main() {
    	fmt.Println("Listening on port 6379")
    	server := pedis.NewServer(&pedis.Config{
    		EnableAof: true,
                    AofFile:   "pedis.aof", // optional
  • 2

    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.


    • Choose either the AOF or RDB mechanism based on our needs and requirements.
    • Implement the chosen mechanism to persist data to disk.
    • Define a file format for storing serialized data on disk.
    • Define a mechanism for recovering data from disk in case of a system failure or other issue.
    • Optimize performance of the persistence mechanism, such as using caching, compression, or parallel I/O.
  • 3

    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.


    • Add an expiration time attribute to each key-value pair in the data store.
    • Implement a mechanism to check the expiration time of each data structure and delete expired keys.
    • Define a mechanism to configure the expiration time for individual keys or for all keys in the data store.