Skip to content

dontloseyourheadsu/CacheServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🦀 CacheServer

A blazingly fast, async, RESP-compatible cache server written in Rust.

Rust Tokio License


📖 Overview

CacheServer is a lightweight, high-performance key-value store built from the ground up using Rust and Tokio. It mimics the core functionality of a standard cache server, providing a familiar interface for caching data with expiration support. Whether you're learning Rust network programming or need a simple, embedded-friendly cache server, this project is designed to be easy to read, configure, and extend.

⚡ Features

  • RESP Protocol Compatible: Speaks the language of RESP. Connect with any RESP client!
  • Async I/O: Powered by tokio for handling thousands of concurrent connections.
  • TTL Support: Set keys with expiration times (SET key value EX seconds).
  • Flexible Configuration: Configure your server using JSON or YAML.
  • TCP Keepalive: Robust connection handling with configurable keep-alive settings.

🛠️ Configuration

Gone are the days of hardcoded constants. CacheServer supports dynamic configuration via file. You can use either .json or .yaml formats.

Configuration Fields

Field Type Default Description
host String 127.0.0.1 The IP address to bind the server to.
port u16 6379 The port to listen on.
idle_timeout_secs u64 300 Disconnect clients after $N$ seconds of inactivity.
keep_alive_time_secs u64 60 TCP keep-alive time.
keep_alive_interval_secs u64 10 TCP keep-alive interval.
cache_cleanup_interval_secs u64 1 How often to sweep for expired keys.

Examples

config.yaml

host: "0.0.0.0"
port: 6379
idle_timeout_secs: 300
keep_alive_time_secs: 60
keep_alive_interval_secs: 10
cache_cleanup_interval_secs: 1

config.json

{
  "host": "127.0.0.1",
  "port": 6379,
  "idle_timeout_secs": 300,
  "keep_alive_time_secs": 60,
  "keep_alive_interval_secs": 10,
  "cache_cleanup_interval_secs": 1
}

🏃 Getting Started

Prerequisites

Installation & Running

  1. Clone the repository:

    git clone https://github.com/dontloseyourheadsu/CacheServer.git
    cd CacheServer
  2. Run the server: By default, it looks for config.json or config.yaml in the current directory.

    cd cache_server
    cargo run --release

    Or specify a config file:

    cargo run --release -- my_config.yaml
  3. Connect: You can use our included client or standard tools:

    cd cache_client
    cargo run
    # > PING
    # PONG
    # > SET mykey "Hello Rust" EX 60
    # OK
    # > GET mykey
    # "Hello Rust"

🤝 How to Contribute

We love contributions! Whether it's fixing a bug, adding a new command, or improving documentation.

  1. Fork the repository.
  2. Create a feature branch (git checkout -b feature/amazing-command).
  3. Commit your changes. Please ensure you run cargo fmt and cargo clippy before committing.
  4. Push to the branch.
  5. Open a Pull Request.

Project Structure

  • cache_server/src/main.rs: Entry point.
  • cache_server/src/handler.rs: Connection handling logic.
  • cache_server/src/cache.rs: In-memory storage and expiration logic.
  • cache_server/src/config.rs: Configuration loading.

Built with ❤️ and 🦀 by dontloseyourheadsu

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages