This is a simple Redis-like in-memory key-value store built using Node.js and TCP sockets.
PING: Replies withPONGECHO: Replies with the same messageSET key value: Stores the key-value pairSET key value PX milliseconds: Stores the key-value pair with expiryGET key: Retrieves the value for the key (if not expired)
Make sure you have Bun installed.
bun install
bun run devThis starts the TCP server on port 6379.
You can use netcat to send raw RESP (Redis Serialization Protocol) commands.
echo -e '*1\r\n$4\r\nPING\r\n' | nc 127.0.0.1 6379Response:
+PONGecho -e '*2\r\n$4\r\nECHO\r\n$5\r\nHello\r\n' | nc 127.0.0.1 6379Response:
$5
Helloecho -e '*3\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n' | nc 127.0.0.1 6379Response:
+OKecho -e '*5\r\n$3\r\nSET\r\n$3\r\nkey\r\n$5\r\nvalue\r\n$2\r\nPX\r\n$4\r\n1000\r\n' | nc 127.0.0.1 6379Response:
+OKecho -e '*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n' | nc 127.0.0.1 6379Response (if key exists):
$5
valueResponse (if key does not exist):
$-1