A simple Redis clone implemented in Golang.
- Supports basic commands.
- Easy to implement any new command.
- Supports two different types of key expiration: passive and random active expiration.
- Tested with the popular Golang Redis client
go-redis
. - Configuration options via JSON or YAML.
- Supports manual execution and Docker deployment.
- Go 1.22+
- Docker (optional)
Clone the repository:
git clone https://github.com/Abdulrahman-Tayara/redis.git
cd redis
Build the project:
go build -o cmd/server/main.go
Run the server with the default settings:
./main
Specify a JSON or YAML config file:
./main -config config.json
or
./main -config config.yaml
Build the Docker image:
docker build -t redis-clone .
Run the container:
docker run -p 6379:6379 redis-clone
To use a custom config file, mount it as a volume:
docker run -p 6379:6379 -v $(pwd)/config.json:/app/config.json redis-clone --config /app/config.json
The server supports configuration through JSON or YAML files. Example configurations:
{
"port": "6379",
"version": "6.0.3",
"proto_version": 3,
"mode": "standalone"
}
port: "6379"
version: "6.0.3"
proto_version: 3
mode: "standalone"
You can test the server using the go-redis
client:
package main
import (
"context"
"fmt"
"github.com/redis/go-redis/v9"
)
func main() {
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
ctx := context.Background()
err := rdb.Set(ctx, "key", "value", 0).Err()
if err != nil {
panic(err)
}
val, err := rdb.Get(ctx, "key").Result()
if err != nil {
panic(err)
}
fmt.Println("key:", val) // Output: key: value
}
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is licensed under the MIT License.