Code: Key-value stores: kv, Redis and memcached
Key-value stores: the code
The programs behind the slides, for Jennifer 0.28.0. The kv programs and session_ratelimit.j need nothing; the others talk to throwaway Redis and memcached containers bound to localhost. The modules (redis.j, memcache.j, kvstore.j, session.j, ratelimit.j, transport.j) ship with the interpreter, so no jvc install is needed. Run everything from this folder.
Servers (stop them with docker rm -f kv-redis kv-redis-auth kv-memcached):
docker run --rm -d --name kv-redis -p 127.0.0.1:16379:6379 redis:7
docker run --rm -d --name kv-redis-auth -p 127.0.0.1:16398:6379 redis:7 redis-server --requirepass example-password
docker run --rm -d --name kv-memcached -p 127.0.0.1:11311:11211 memcached:1.6kv_basics.j:kv.setwith a TTL,incr,addand expiry ("kv: a store in the process"). Run:jennifer run kv_basics.jkv_shared.j: four tasks incrementing through copies of one handle ("The handle is shared"). Run:jennifer run kv_shared.jkv_types.j: strict types, a parsedjson.Value, andkv.openFile; a second run printsrun 2("kv: strict types, parsed values, a file"). Run:jennifer run kv_types.j(writesstate.kvhere; delete it to start over)redis_basics.j: connecting, strings, TTLs, counters, hashes, lists, sets ("Redis: connecting", "Redis: strings, TTLs, counters", "Redis: hashes, lists, sets"). Needskv-redis. Run:jennifer run redis_basics.jredis_pipeline.j:pipeline,multi/exec("Redis: pipelines and transactions"). Needskv-redis. Run:jennifer run redis_pipeline.jredis_pubsub.j: a subscriber on its own connection in a task, then a publish ("Redis: pub/sub"). Needskv-redis. Run:jennifer run redis_pubsub.jredis_errors.j:ERR,WRONGTYPE, a closed port (16999), a wrong password and a read timeout ("Redis: when it says no"). Needskv-redis. Run:jennifer run redis_errors.jredis_auth.j:WRONGPASSandNOAUTHagainstrequirepass("Redis: when it says no"). Needskv-redis-auth; the passwordexample-passwordis a placeholder. Run:jennifer run redis_auth.jmemcached.j: set, add, incr, decr,gets/cas,getMulti, a value over the 1 MiB item limit and a key with a space ("memcached: a narrower model", "memcached: check-and-set", "memcached: when it says no"). Needskv-memcached. Run:jennifer run memcached.jbackends.j: onekvstore.incrWindowcall against the in-process store, memcached and Redis ("kvstore: one line picks the backend"). Needskv-redisandkv-memcached. Run:jennifer run backends.jsession_ratelimit.j:session.create,save,rotateand a fixed-window rate limiter on an in-process store ("session and ratelimit on top"). Run:jennifer run session_ratelimit.j
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 2.7 KiB | raw |
| backends.j | 943 B | raw |
| kv_basics.j | 510 B | raw |
| kv_shared.j | 386 B | raw |
| kv_types.j | 624 B | raw |
| memcached.j | 1.0 KiB | raw |
| redis_auth.j | 566 B | raw |
| redis_basics.j | 1.1 KiB | raw |
| redis_errors.j | 967 B | raw |
| redis_pipeline.j | 690 B | raw |
| redis_pubsub.j | 646 B | raw |
| session_ratelimit.j | 905 B | raw |