gvalkey

module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2025 License: MIT

README ΒΆ

GValkey

A Redis-compatible in-memory cache implemented in Go

Go version Go report GitHub License

πŸ“‹ Table of Contents

πŸš€ About

GValkey is a lightweight, Redis-compatible in-memory cache written in Go. It implements the Redis Serialization Protocol (RESP) and provides a subset of Redis functionality with a focus on simplicity.

✨ Features

  • Redis Protocol Compatible: Implements RESP (Redis Serialization Protocol)
  • In-Memory: Fast key-value storage with automatic TTL support
  • Concurrent Safe: Thread-safe operations using Go's sync.Map
  • Automatic Cleanup: Background garbage collection for expired keys
  • Graceful Shutdown: Proper server shutdown handling
  • Structured Logging: Comprehensive logging with slog
  • Command Validation: Proper argument validation for Redis commands

πŸ“¦ Installation

Prerequisites

  • Go 1.24.3 or higher (for building from source)
  • Docker (for running with Docker)
# Pull the latest image
docker pull ghcr.io/playerneo42/gvalkey:latest

# Run GValkey container
docker run -d \
  --name gvalkey \
  -p 6379:6379 \
  ghcr.io/playerneo42/gvalkey:latest

Using Docker Compose

services:
  gvalkey:
    image: ghcr.io/playerneo42/gvalkey:latest
    ports:
      - "6379:6379"
    restart: unless-stopped

Building from Source

# Clone the repository
git clone https://github.com/PlayerNeo42/gvalkey
cd gvalkey

# Build the server
go build -o gvalkey ./cmd/server

# Run the server
./gvalkey

Connecting with Redis CLI

Since GValkey implements the Redis protocol, you can use any Redis-compatible client:

# Using redis-cli
redis-cli -h localhost -p 6379

# Test basic commands
127.0.0.1:6379> SET mykey "Hello, GValkey!"
OK
127.0.0.1:6379> GET mykey
"Hello, GValkey!"
127.0.0.1:6379> DEL mykey
(integer) 1

βš™οΈ Configuration

GValkey can be configured using environment variables. All configuration options have sensible defaults.

Environment Variables

Variable Description Default Valid Values
GVK_HOST Server bind address 0.0.0.0 Valid hostname or IP address
GVK_PORT Server listen port 6379 1-65535
GVK_LOG_LEVEL Logging level INFO DEBUG, INFO, WARN, ERROR

πŸ“ Supported Commands

Command Description Status
SET key value [EX seconds] [PX milliseconds] [NX|XX] [GET] Set a key-value pair with optional expiration and conditions βœ…
GET key Retrieve value by key βœ…
DEL key [key ...] Delete one or more keys βœ…

SET Command Options

  • EX seconds: Set expiration in seconds
  • PX milliseconds: Set expiration in milliseconds
  • NX: Only set if key doesn't exist
  • XX: Only set if key already exists
  • GET: Return the old value when setting

πŸ› οΈ Development

Code Formatting && Linting

golangci-lint fmt 
golangci-lint run --fix

Running Tests

go test ./...

Or you can do make check for both steps.

Benchmark

make bench

πŸ“„ License

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

πŸ™ Acknowledgments

Directories ΒΆ

Path Synopsis
cmd
server command
internal
log
Package resp provides RESP (Redis Serialization Protocol) types and utilities.
Package resp provides RESP (Redis Serialization Protocol) types and utilities.
Package store provides multiple thread-safe in-memory key-value store implementations.
Package store provides multiple thread-safe in-memory key-value store implementations.
eventloop
Package eventloop implements a simple event loop store that uses a single goroutine to handle all commands.
Package eventloop implements a simple event loop store that uses a single goroutine to handle all commands.
naive
Package naive implements a thread-safe in-memory key-value store using sync.Map.
Package naive implements a thread-safe in-memory key-value store using sync.Map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL