Skip to content

Commit

Permalink
tweak, tweak, tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Feb 17, 2025
1 parent 09c3c3f commit 68a875b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
2 changes: 1 addition & 1 deletion _js/repl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
42 changes: 30 additions & 12 deletions _posts/2023-12-17-bradis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<sup>[*](#free-ish)</sup> Redis.
free<sup>[1](#free-ish)</sup> Redis.

*However!*

Expand All @@ -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<sup>[2](#wasm-caveats)</sup>, 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

<div id="repl-one"></div>

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

<div id="repl-two"></div>

Expand All @@ -75,10 +87,16 @@ Also, try out some pubsub!

<hr>

<a id="free-ish">*</a> [License changes][license] notwithstanding.
<span id="free-ish">1.</span> [License changes][license] notwithstanding.

<span id="wasm-caveats">2.</span> 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/

0 comments on commit 68a875b

Please sign in to comment.