A small, educational concurrent key-value TCP server in Rust.
This project implements a simple in-memory key-value store that accepts plain-text commands over TCP. It's designed to demonstrate basic concurrency (thread-per-connection) using an Arc<Mutex<HashMap<_, _>>> and a minimal custom protocol for GET/SET/DEL operations.
- Simple, human-readable line-based protocol
- Concurrent clients handled with threads
- In-memory storage using
HashMapprotected byMutex - Minimal dependency surface (std only)
All commands are single-line and terminated by a newline (\n). Arguments are separated by whitespace.
GET <key>— returns the value ornot foundif missingSET <key> <value>— sets a key to a value and responds withOKDEL <key>— deletes a key and responds with the deleted value ornot found
Note: Commands are case-sensitive (expect GET, SET, DEL).
Requirements: Rust (stable) toolchain.
Build and run locally:
# from the project root
cargo runBy default the server listens on 127.0.0.1:7978 and prints a message on startup:
concurrent server listening on port localhost:7978
Open a new terminal and run:
# set a key
printf "SET mykey hello\n" | nc 127.0.0.1 7978
# => OK
# get the key
printf "GET mykey\n" | nc 127.0.0.1 7978
# => hello
# delete the key
printf "DEL mykey\n" | nc 127.0.0.1 7978
# => deleted helloYou can also connect with telnet or any TCP client and issue newline-terminated commands interactively.
- This is an educational example, not intended for production use.
- The server uses a global
Mutex, so concurrent access is serialized. - No persistence — data is lost when the process exits.
- Error messages and command validation are intentionally minimal.
Contributions and improvements are welcome. Open an issue or submit a pull request with changes or ideas.
MIT — see LICENSE (or add one) for details.
Thanks for checking out kv-concurrent! If you'd like, I can also:
- add example client scripts, or
- add a small test harness that exercises commands concurrently.