← All showcases

kvstore — a key-value server with its own protocol

Source on GitHub ↗

An in-memory key-value store with a Redis-flavoured text protocol, over raw TCP. Like the chat server it is concurrent — one start thread per connection — but instead of broadcasting, the connections share a single mutable store guarded by a Lock, and each command line gets a reply. It's the "network protocol" showcase: no HTTP, just a line protocol you can type by hand.

Run it

build/rakupp showcase/kvstore/kvstore.raku          # listens on 127.0.0.1:6380
PORT=7000 build/rakupp showcase/kvstore/kvstore.raku
# or compile a standalone binary:
build/rakupp --exe -o kvstore showcase/kvstore/kvstore.raku && ./kvstore

Then connect with any line-oriented TCP client:

nc 127.0.0.1 6380

A session

$ nc 127.0.0.1 6380
rakupp-kv ready. One command per line; HELP for the list.
SET name ada
OK
GET name
ada
SET greeting "hello world"
OK
GET greeting
hello world
INCR hits
1
INCR hits
2
APPEND name " lovelace"
12
GET name
ada lovelace
KEYS
greeting hits name
DBSIZE
3
DEL name
1
GET name
(nil)
QUIT

(The short lines are what you type; the line under each is the server's reply.)

Commands

CommandReply
SET key value…OK — value may be "quoted to keep spaces"
GET keythe value, or (nil)
DEL key…count of keys removed
EXISTS key1 / 0
INCR key / DECR keythe new integer value
APPEND key valuethe new string length
KEYSall keys, sorted
DBSIZEnumber of keys
FLUSHALLOK — clears the store
PING [msg]PONG (or the echoed message)
HELPthe command list
QUITcloses the connection

How it works