Thanks to visit codestin.com
Credit goes to github.com

Skip to content

A high-performance, in-memory key-value database written in Go, capable of handling 100k+ requests per second. Lightweight, concurrent-safe, and RESP-compatible with support for strings, counters, and lists.

Notifications You must be signed in to change notification settings

bmqube/VolatileDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VolatileDB

A lightweight, in-memory key-value database implementation written in Go, compatible with Redis protocol (RESP).

Features

  • In-Memory Storage: Fast key-value operations stored in memory
  • Redis Protocol Compatible: Uses RESP (Redis Serialization Protocol) for communication
  • Concurrent Safe: Thread-safe operations with proper synchronization
  • Extensible Architecture: Clean design patterns make it easy to add new commands
  • TCP Server: Handles multiple concurrent client connections

Supported Commands

  • PING [message] - Test server connectivity
  • ECHO <message> - Echo back the given message
  • SET <key> <value> [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds] - Set a key-value pair with optional expiration
  • GET <key> - Get value by key
  • DEL <key> [key ...] - Delete one or more keys
  • EXISTS <key> - Checks if a key is present
  • INCR <key> - Increments a stored number by one
  • DECR <key> - Decrements a stored number by one
  • LPUSH <key> element [element ...] - insert all the values at the head of a list.
  • RPUSH <key> element [element ...] - insert all the values at the tail of a list.
  • LRANGE <key> <start> <stop> - Returns the specified elements of the list stored at key.

Quick Start

Prerequisites

  • Go 1.19 or higher

Installation

git clone https://github.com/bmqube/VolatileDB.git
cd VolatileDB
go build -o volatiledb

Running the Server

./volatiledb

The server will start listening on port 6969 by default.

Connecting to the Server

You can connect using any Redis client or tools like redis-cli, telnet, or nc:

# Using redis-cli (if installed)
redis-cli -p 6969

# Using telnet
telnet localhost 6969

# Using netcat
nc localhost 6969

Example Usage

# Connect to the server
$ redis-cli -p 6969

# Test connectivity
127.0.0.1:6969> PING
PONG

127.0.0.1:6969> PING Hello
Hello

# Echo command
127.0.0.1:6969> ECHO test
test

# Set and get values
127.0.0.1:6969> SET mykey myValue
OK

127.0.0.1:6969> GET mykey
myValue

127.0.0.1:6969> GET nonexistent
(nil)

Project Structure

VolatileDB/
├── commands/           # Command implementations
│   ├── registry.go     # Command registry
│   ├── ping.go         # PING command
│   ├── echo.go         # ECHO command
│   ├── set.go          # SET command
│   ├── get.go          # GET command
│   ├── decr.go         # DECR command
│   ├── incr.go         # INCR command
│   ├── del.go          # DEL command
│   ├── exists.go       # EXISTS command
│   ├── lpush.go        # LPUSH command
│   ├── rpush.go        # RPUSH command
│   ├── lrange.go       # LRANGE command
│   └── interface.go    # base command interface
├── handlers/           # Connection handling
│   └── handler.go      # TCP connection handler
├── models/             # Data models
│   └── message.go      # RESP message structures
├── resp/               # RESP protocol implementation
│   ├── serializer.go   # Message serialization
│   ├── deserializer.go # Message deserialization
│   ├── builder.go      # Message building
│   └── writer.go       # Response writing
├── store/              # Storage implementations
│   └── storage.go      # Storage interface & In-memory storage
└── main.go             # Server entry point

Development

Adding New Commands

  1. Create a new command struct implementing the Command interface:
type YourCommand struct{}

func (c *YourCommand) Execute(args []models.Message, store store.Storage) models.Message {
    // Your implementation
}

func (c *YourCommand) ValidateArgs(args []models.Message) error {
    // Validation logic
}
  1. Register it in the command registry:
registry.Register("yourcommand", &YourCommand{})

Performance

  • Concurrency: Handles multiple simultaneous connections
  • Memory: All data stored in memory for maximum speed
  • Protocol: Efficient RESP protocol for minimal overhead

Benchmarks

Performance comparison between VolatileDB and Redis: Benchmark Results

Limitations

  • Persistence: Data is not persisted to disk (volatile by design)
  • Memory: Limited by available system memory
  • Commands: Subset of Redis commands implemented

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is open source and available under the MIT License.

Acknowledgments

  • Inspired by Redis and its RESP protocol
  • Built as a learning project to understand database internals

About

A high-performance, in-memory key-value database written in Go, capable of handling 100k+ requests per second. Lightweight, concurrent-safe, and RESP-compatible with support for strings, counters, and lists.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages