Skip to content

DNahar74/PulseDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

81 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ PulseDB

License: MIT Go Version Build Status

A high-performance, lightweight Redis clone written in Go, implementing the RESP2 protocol from scratch. This project serves as a deep dive into building low-level systems and understanding the inner workings of Redis.

⚠️ Educational Project: This is primarily an educational implementation designed for learning purposes. For production use, consider Redis or KeyDB.

🎯 Quick Start

# Using Docker (Recommended)
docker-compose up --build

# Or build from source
go build -o PulseDB ./cmd/PulseDB
./PulseDB

✨ Features

Core Functionality

  • πŸ”§ Custom RESP2 Protocol: Complete implementation of Redis Serialization Protocol v2
  • πŸ“Š Redis Data Types: Support for all core Redis data types:
    • Simple Strings (+OK\r\n)
    • Errors (-ERROR message\r\n)
    • Integers (:100\r\n)
    • Bulk Strings ($6\r\nfoobar\r\n)
    • Arrays (*2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n)
  • ⚑High Concurrency: Thread-safe operations with concurrent client handling
  • πŸ’Ύ Persistence: AOF (Append Only File) and memory snapshots
  • ⏰ Key Expiration: TTL support with automatic cleanup

Performance & Reliability

  • πŸ”’ Thread Safety: Robust concurrent access with RWMutex
  • πŸ“ˆ Benchmarks: Comprehensive performance testing included
  • πŸ§ͺ Test Coverage: Extensive test suite with >95% coverage
  • πŸ“Š Memory Efficient: Optimized memory usage patterns

πŸ“ Project Structure

PulseDB/
β”œβ”€β”€ cmd/
β”‚   └── PulseDB/        # Main application entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ command/        # Command parsing and execution
β”‚   β”œβ”€β”€ resp/           # RESP2 protocol implementation
β”‚   β”œβ”€β”€ server/         # TCP server setup and client handling
β”‚   β”œβ”€β”€ store/          # In-memory data storage with persistence
β”‚   └── utils/          # Utility functions and helpers
β”œβ”€β”€ bin/                # Compiled binaries
β”œβ”€β”€ docker-compose.yml  # Docker setup for easy deployment
β”œβ”€β”€ Dockerfile          # Container configuration
β”œβ”€β”€ Makefile           # Build automation
β”œβ”€β”€ go.mod             # Go module dependencies
└── README.md          # Project documentation

πŸ› οΈ Getting Started

Prerequisites

Installation Options

Option 1: Using Docker (Recommended)

# Clone the repository
git clone https://github.com/DNahar74/PulseDB.git
cd PulseDB

# Run with Docker Compose
docker-compose up --build

# The server will be available at localhost:6378

Option 2: Build from Source

# Clone the repository
git clone https://github.com/DNahar74/PulseDB.git
cd PulseDB

# Build using Makefile
make build

# Or build manually
go build -o bin/PulseDB ./cmd/PulseDB

# Run the server
./bin/PulseDB

Option 3: Development Mode

# Run directly with Go
make run

# Or manually
go run ./cmd/PulseDB

Configuration

PulseDB accepts the following command-line flags:

  • -addr : Server address (default: :6379)
  • -v : Show version information
  • -verbose : Enable verbose logging
./bin/PulseDB -addr :6378 -verbose

πŸ§ͺ Usage

Connecting to PulseDB

Once the server is running, you can connect using various Redis clients:

Using Redis CLI

# If you have redis-cli installed
redis-cli -p 6379

# Using Docker with redis-cli
docker run -it --rm redis:alpine redis-cli -h host.docker.internal -p 6379

Using Telnet

telnet localhost 6379

Using Docker Compose Redis CLI

# Start the redis-cli service defined in docker-compose.yml
docker-compose run --rm redis-cli

Basic Commands

# Test connection
PING

# Set and get values
SET mykey "Hello, PulseDB!"
GET mykey

# Set with expiration (100 seconds)
SET tempkey "temporary value" EX 100
GET tempkey

# Delete keys
DEL mykey tempkey

# Echo command
ECHO "Hello World"

πŸ”§ Development

Building

# Build for current platform
make build

# Build for all platforms
make build-all

# Clean build artifacts
make clean

Testing

# Run all tests
make test

# Run tests with coverage
make test-coverage

# Run benchmarks
make benchmark

Code Quality

# Format code
make fmt

# Run linter
make lint

# Run security checks
make security

🐳 Docker

The project includes Docker support for easy deployment:

# Build Docker image
docker build -t pulsedb .

# Run container
docker run -p 6379:6378 pulsedb

# Using docker-compose for full setup
docker-compose up -d

πŸ“Š Performance

PulseDB is designed for high performance with the following characteristics:

  • Concurrent Connections: Handles thousands of concurrent clients
  • Memory Efficiency: Optimized data structures for minimal memory footprint
  • Protocol Efficiency: Full RESP2 implementation with minimal overhead
  • Persistence: AOF and snapshot mechanisms for data durability

Benchmarks

Run benchmarks to test performance:

make benchmark

πŸ› οΈ Implemented Commands

🟒 PING

  • Description: Tests the connection with the server.
  • Usage:
    PING
  • Response:
    +PONG
    

πŸ—£οΈ ECHO

  • Description: Returns the input string.
  • Usage:
    ECHO "hello world"
  • Response:
    "hello world"
    

πŸ’Ύ SET

  • Description: Stores a key with a string value. Optional expiry flag in seconds.
  • Usage:
    SET hello world
    SET hello world EX 100  # Key expires in 100 seconds
  • Response:
    +OK
    

πŸ“₯ GET

  • Description: Retrieves the value of the given key.
  • Usage:
    GET hello
  • Response (if found):
    "world"
    

❌ DEL

  • Description: Deletes the specified key.
  • Usage:
    DEL hello
  • Response:
    +OK
    

πŸ“š RESP2 Protocol Overview

PulseDB implements the Redis Serialization Protocol (RESP) version 2 for client-server communication.

Data Types

Type Format Example
Simple Strings +<string>\r\n +OK\r\n
Errors -<error>\r\n -ERROR Invalid command\r\n
Integers :<number>\r\n :1000\r\n
Bulk Strings $<length>\r\n<string>\r\n $6\r\nfoobar\r\n
Arrays *<count>\r\n<element1>...<elementN> *2\r\n$3\r\nfoo\r\n$3\r\nbar\r\n

For detailed protocol specification, see the Redis Protocol documentation.


πŸš€ Roadmap

Completed βœ…

  • RESP2 protocol implementation
  • Basic Redis commands (PING, ECHO, SET, GET, DEL)
  • Key expiration (TTL)
  • AOF persistence
  • Memory snapshots
  • Docker support
  • Concurrent client handling

In Progress 🚧

  • More Redis commands (INCR, DECR, LPUSH, RPOP, etc.)
  • Redis data structures (Lists, Sets, Hashes)
  • Pub/Sub functionality
  • Clustering support

Future Plans πŸ“‹

  • RESP3 protocol support
  • Redis modules compatibility
  • Replication
  • Lua scripting support

🧱 Contributing

We welcome contributions! Here's how you can help:

Getting Started

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/yourusername/PulseDB.git
  3. Create a feature branch: git checkout -b feature/amazing-feature
  4. Make your changes
  5. Test your changes: make test
  6. Commit your changes: git commit -m 'Add amazing feature'
  7. Push to the branch: git push origin feature/amazing-feature
  8. Open a Pull Request

Development Guidelines

  • Follow Go best practices and conventions
  • Add tests for new functionality
  • Update documentation for API changes
  • Run make fmt and make lint before committing
  • Write clear, descriptive commit messages

Issues

Found a bug or have a feature request? Please open an issue with:

  • Clear description of the problem/feature
  • Steps to reproduce (for bugs)
  • Expected vs actual behavior
  • Go version and OS information

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™Œ Acknowledgements

  • Redis - For the inspiration and protocol specification
  • Go Team - For creating an amazing programming language
  • Docker - For simplifying deployment and development
  • Open Source Community - For continuous inspiration and support

πŸ“ž Contact

Project Maintainer: DNahar74


⭐ Star this repository if you found it helpful! ⭐

About

This is me trying to implement redis

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published