A blazingly fast, async, RESP-compatible cache server written in Rust.
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.
- RESP Protocol Compatible: Speaks the language of RESP. Connect with any RESP client!
- Async I/O: Powered by
tokiofor 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.
Gone are the days of hardcoded constants. CacheServer supports dynamic configuration via file. You can use either .json or .yaml formats.
| 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 |
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. |
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{
"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
}- Rust & Cargo (Latest Stable)
-
Clone the repository:
git clone https://github.com/dontloseyourheadsu/CacheServer.git cd CacheServer -
Run the server: By default, it looks for
config.jsonorconfig.yamlin the current directory.cd cache_server cargo run --releaseOr specify a config file:
cargo run --release -- my_config.yaml
-
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"
We love contributions! Whether it's fixing a bug, adding a new command, or improving documentation.
- Fork the repository.
- Create a feature branch (
git checkout -b feature/amazing-command). - Commit your changes. Please ensure you run
cargo fmtandcargo clippybefore committing. - Push to the branch.
- Open a Pull Request.
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