From 68a875b3ee374f804de7cad2b2c0d19186a92c90 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Mon, 17 Feb 2025 12:45:40 -0500 Subject: [PATCH] tweak, tweak, tweak --- _js/repl.tsx | 2 +- _posts/2023-12-17-bradis.md | 42 ++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/_js/repl.tsx b/_js/repl.tsx index ee33f87..26be622 100644 --- a/_js/repl.tsx +++ b/_js/repl.tsx @@ -6,7 +6,7 @@ import init, { Bradis, JsRespValue } from "bradis-web" await init() const bradis = Bradis.create() -setInterval(() => { bradis.tick() }, 100) +setInterval(() => { bradis.tick() }, 200) const RespValue = ({ value }: { value: JsRespValue }) => { switch (value.tag) { diff --git a/_posts/2023-12-17-bradis.md b/_posts/2023-12-17-bradis.md index 3c4c549..0a1b16a 100644 --- a/_posts/2023-12-17-bradis.md +++ b/_posts/2023-12-17-bradis.md @@ -27,7 +27,7 @@ even if it never lives in production. Anyways. I started to write Redis with Rust, and several years later I have something that is decidedly not a Redis. It's a small piece of a Redis, which is not particularly valuable given the existence of a full, -free[*](#free-ish) Redis. +free[1](#free-ish) Redis. *However!* @@ -54,19 +54,31 @@ it declares my existence. Brad is. (I am.) ### What is it then? -Ok. If it's not an entire Redis, what is it? It's lots of things! But here's -one of them. It's a repl you can get results from. Try some of these things: - -* `set x foo` followed by `get x` -* get the current list of commands with `command list` -* `rpush l a b c` followed by `lrange l 0 -1` +One of my favorite things about Rust is its support for compiling to [web +assembly][wasm]. With a bit of work and a few +caveats[2](#wasm-caveats), you can run Rust code in the browser. The +repl below is Bradis running in the browser via WASM. Try out some Redis +commands! + +* `set x foo` - set a value +* `get x` - get a value +* `command list` - get a list of commands +* `hset h x 1` - set values in a hash +* `rpush l a b c` - push values into a list +* `sadd s x y z` - push values into a set +* `zadd z 1 x 2 y 3 z` - add values to a sorted set +* `multi` - start a transaction +* `exec` - execute a transaction +* `client info` - get info about the current client
-Also, try out some pubsub! +Also, try some commands that use two clients. -* `subscribe news` in the repl above -* `publish news boom` in the repl below +* `subscribe news` - subscribe to a channel above +* `publish news boom` - publish to a channel below +* `blpop l 0` - block while waiting for a value above +* `rpush l a b c` - add a value for the command above
@@ -75,10 +87,16 @@ Also, try out some pubsub!
-* [License changes][license] notwithstanding. +1. [License changes][license] notwithstanding. + +2. There are a few capabilities that aren't +currently supported in the browser (e.g. threads) so they have to be emulated +or left out. [license]: https://redis.io/blog/redis-adopts-dual-source-available-licensing/ [redis]: https://redis.io -[respite]: http://github.com/braddunbar/respite +[respite]: https://github.com/braddunbar/respite [resp]: https://redis.io/docs/latest/develop/reference/protocol-spec/ [rust]: https://www.rust-lang.org/ +[wasm]: https://webassembly.org/ +[tokio]: https://tokio.rs/