A lightweight, in-memory key-value database implementation written in Go, compatible with Redis protocol (RESP).
- 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
PING [message]- Test server connectivityECHO <message>- Echo back the given messageSET <key> <value> [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds]- Set a key-value pair with optional expirationGET <key>- Get value by keyDEL <key> [key ...]- Delete one or more keysEXISTS <key>- Checks if a key is presentINCR <key>- Increments a stored number by oneDECR <key>- Decrements a stored number by oneLPUSH <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.
- Go 1.19 or higher
git clone https://github.com/bmqube/VolatileDB.git
cd VolatileDB
go build -o volatiledb./volatiledbThe server will start listening on port 6969 by default.
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# 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)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
- Create a new command struct implementing the
Commandinterface:
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
}- Register it in the command registry:
registry.Register("yourcommand", &YourCommand{})- Concurrency: Handles multiple simultaneous connections
- Memory: All data stored in memory for maximum speed
- Protocol: Efficient RESP protocol for minimal overhead
Performance comparison between VolatileDB and Redis:
- Persistence: Data is not persisted to disk (volatile by design)
- Memory: Limited by available system memory
- Commands: Subset of Redis commands implemented
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is open source and available under the MIT License.
- Inspired by Redis and its RESP protocol
- Built as a learning project to understand database internals