Skip to content

Repository files navigation

Java Spring

redis-java

A from-scratch, Redis-protocol-compatible key-value server written in Java and Spring. It speaks the real Redis wire protocol (RESP) over raw TCP sockets, and supports an in-memory store with expiry, transactions, and master–replica replication — plus a full Docker, CI, and Kubernetes deployment setup around it.

Features

  • RESP protocol — a hand-rolled encoder/decoder for Redis's actual wire format, not a borrowed library
  • Core commandsPING, ECHO, SET (with millisecond expiry via PX), GET, INCR
  • TransactionsMULTI / EXEC / DISCARD, applied atomically against the store
  • Replication — master/replica roles, a real PSYNC full-resync handshake, live command propagation, WAIT, and support for chained replicas
  • Containerized — multi-stage Dockerfile producing a small runtime image
  • CI/CD — an Azure Pipelines build/push pipeline with a self-hosted Docker-in-Docker agent
  • Kubernetes-ready — a Helm chart, tested locally against a kind cluster

Supported commands

Command Notes
PING
ECHO <msg>
SET <key> <value> [PX <ms>] optional expiry in milliseconds
GET <key>
INCR <key>
MULTI / EXEC / DISCARD transactions
INFO replication
REPLCONF, PSYNC, WAIT replication internals

Getting started

Prerequisites: Java 23, Maven

./your_program.sh                                            # build + start a master on port 6379
./your_program.sh --port 6380 --replicaof "localhost 6379"    # start a replica of the above

Try it with redis-cli:

redis-cli -p 6379 PING
redis-cli -p 6379 SET foo bar
redis-cli -p 6379 GET foo

Run the test suite:

mvn test

Documentation

DOCUMENTATION.md is a full guided walkthrough of this codebase — architecture, the RESP protocol byte by byte, a component-by-component tour with diagrams, the concurrency model, design trade-offs, and an honest list of what's simplified compared to real Redis (including a couple of things confirmed by actually testing the server). It also has a set of interview-style questions and answers based on this project, and assumes little to no prior Java experience.

Deployment

Docker
docker build -t redis-java .
docker run -p 6379:6379 redis-java
Kubernetes (kind + Helm)
kind create cluster --config kind/k.yml --name cluster-name
docker build -t beelzekamibub/redis-java:latest .
kind load docker-image beelzekamibub/redis-java:latest --name cluster-name
helm install redis-app redis-chart
CI (Azure Pipelines)

azure-pipelines.yml builds and pushes the Docker image on every push to master, running on a self-hosted agent (see dind/) rather than a hosted pool.

Full context and rationale for each of these lives in DOCUMENTATION.md.

Known limitations

This is a learning project, not a Redis replacement — a few things worth knowing before relying on it for anything real:

  • A full resync always sends an empty snapshot; a replica only receives writes made after it connects, never the master's existing data
  • Standalone INCR has a real, confirmed race condition under concurrent load
  • No persistence to disk — a restart loses everything

The complete list, with explanations, is in DOCUMENTATION.md.

Project structure

src/main/java/
├── Main.java              entry point
├── Config/                Spring wiring
└── Components/
    ├── Server/              RedisConfig, MasterTcpServer, SlaveTcpServer
    ├── Service/              RESP protocol codec, command dispatch
    ├── Repository/           the in-memory store
    └── Infra/                connection/replica bookkeeping

See DOCUMENTATION.md for the fully annotated version of this tree.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages