Skip to content

Redis broker

ruststream-fred runs a RustStream service on Redis. Redis Streams is a log, like Kafka: a subscription reads it through a consumer group and acknowledges each entry it handles. Lists and Pub/Sub are here as well. With the testing feature a test runs the service's own app on a Redis modelled in process, so tests run without a server.

ruststream = { version = "0.7", features = ["macros"] }
ruststream-fred = "0.7"
serde = { version = "1", features = ["derive"] }

RedisBroker::standalone is synchronous and does no I/O: the runtime opens the connection at startup and closes it at shutdown.

You name a publish policy when you register a handler: RedisPublish for streams, RedisPubSubPublish for channels, RedisListPublish for lists. The runtime constructs the publisher from that policy on the connected broker, so publishing before connect is not representable.

The policy covers the publish, with one setting left to the message itself. XADD, LPUSH and PUBLISH carry the key or the channel and the value, so a handler body usually writes .message(&value).publish() and nothing else; the exception is the partition key, a step on that builder. A body that sets one imports this crate's prelude and names the options type in its bound; see partition keys.

Scaffold a service

Generate a runnable starter with cargo generate, one template per transport:

cargo generate --git https://github.com/powersemmi/ruststream-fred templates/redis-stream
cargo generate --git https://github.com/powersemmi/ruststream-fred templates/redis-pubsub
cargo generate --git https://github.com/powersemmi/ruststream-fred templates/redis-list

Topologies

Three named constructors pick the topology:

crates/ruststream-fred/examples/fred_topologies.rs
// A single server, addressed by URL.
let _standalone = RedisBroker::standalone("redis://localhost:6379");

// A cluster: one reachable seed node is enough, the rest is discovered.
let _cluster = RedisBroker::cluster(["127.0.0.1:7000", "127.0.0.1:7001"]);

// Sentinel: the monitored primary's name, then the sentinels that watch it.
let _sentinel = RedisBroker::sentinel("mymaster", ["127.0.0.1:26379"]);

Where the rest is

The reference on docs.rs opens with the crate's own textbook, one section per topic:

Handlers, routers, codecs and middleware come from the framework, whose own entry pages start at the RustStream site.