Path: redb-route/redb.Route.Redis/README.md Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Redis/README.md ---- # redb.Route.Redis > Documentation and articles: Redis transport for redb.Route. Pub/Sub, Streams, key-value, lists, sorted sets — every Redis data structure is reachable as an endpoint URI via StackExchange.Redis; the builder has factories for keys, Pub/Sub, streams and lists, and `Redis.Command(operation, key)` for the rest. [![NuGet](https://img.shields.io/nuget/v/redb.Route.Redis?label=NuGet&color=blue)](https://www.nuget.org/packages/redb.Route.Redis) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue)](../../LICENSE) ## Installation ```bash dotnet add package redb.Route.Redis ``` ## Usage ### URI Format ``` redis:OPERATION:resource?connectionString=localhost:6379&... ``` The operation is the first path segment (`SET`, `GET`, `PUBLISH`, `SUBSCRIBE`, `XADD`, `XREAD`, `BLPOP`, …), the resource — key, channel or stream — follows it: `redis:SET:session:42?ttl=300`, `redis:SUBSCRIBE:notifications`. `redis:SET/session/42` works too. A parameter the endpoint cannot read (a misspelt option, a value of the wrong type) is refused by name when the endpoint is created. ### Fluent DSL ```csharp using redb.Route.Redis; // Pub/Sub — subscribe From(Redis.Subscribe("notifications").Connection("localhost:6379")) .Log("Received: ${body}") .To("direct://process"); // Pub/Sub — publish From("direct://outbound") .To(Redis.Publish("events").Connection("localhost:6379")); // Streams — consumer group From(Redis.XRead("order-stream") .Connection("localhost:6379") .ConsumerGroup("processors") .ConsumerName("node-1") .StreamReadCount(100)) .To("direct://handle"); // Key-Value From("direct://cache") .To(Redis.Set("session:user-123") .Connection("localhost:6379") .Ttl(3600)); // Lists From("direct://enqueue") .To(Redis.LPush("task-queue").Connection("localhost:6379")); ``` ## Fluent Builder API | Category | Methods | |----------|---------| | **Connection** | `.Connection()`, `.Database()`, `.Password()`, `.ConnectionFactory()` | | **Key-Value** | `Redis.Set()`, `Redis.Get()`, `Redis.Del()`, `Redis.Exists()`, `Redis.Expire()`, `Redis.Incr()`, `Redis.Decr()`, `Redis.SetNx()` | | **Pub/Sub** | `Redis.Publish()`, `Redis.Subscribe()`, `Redis.PSubscribe()` | | **Streams** | `Redis.XAdd()`, `Redis.XRead()`, `Redis.XGroup()`, `.ConsumerGroup()`, `.ConsumerName()`, `.StreamMaxLength()`, `.StreamReadCount()`, `.StreamBlockTime()`, `.StreamStartPosition()`, `.AckMode()`, `.StreamClaimMinIdle()`, `.Batching()`, `.MaxBatchMessages()`, `.PollTimeoutMs()`, `.BatchingIntervalMs()` | | **Lists** | `Redis.LPush()`, `Redis.RPush()`, `Redis.LPop()`, `Redis.RPop()`, `Redis.LLen()`, `Redis.LRange()`, `.ProcessingList()` | | **Any operation** | `Redis.Command(operation, key)` — the factories above cover keys, Pub/Sub, streams and lists; every other operation (`HSET`, `ZADD`, `GEOADD`, `BLPOP`, …) is built with it | | **Options** | `.Ttl()`, `.Transacted()`, `.PollDelay()`, `.UsePattern()`, `.CustomCommand()` | > Most builder methods accept both constant values and `IExpression` for runtime resolution via the expression engine. `Redis.Command(operation, key)` names an **operation** of this connector. The `COMMAND` operation is something else: a raw Redis command, named with `.CustomCommand("PING")` (or the `redbRedis.Command` header) and run through `ExecuteAsync`. ## Consumers and delivery | Consumer | How it reads | A failed route | |---|---|---| | `SUBSCRIBE` / `PSUBSCRIBE` | Pub/Sub; `PSUBSCRIBE` subscribes to a pattern (`events.*`), `usePattern` makes `SUBSCRIBE` do so too | lost: Pub/Sub keeps nothing | | `XREAD` / `XGROUP` with `consumerGroup` | `XREADGROUP`, acknowledged (`XACK`) after the route succeeded | stays pending; `streamClaimMinIdleMs` claims it again (`XAUTOCLAIM`) once it idled that long — a dead consumer's entries too | | the same with `ackMode=auto` | `XREADGROUP NOACK`: delivered when read | not read again (at-most-once) | | `XREAD` without a group | a position of its own, moved past every entry read; starts at the entries added from now on, or at `streamStartPosition` (`0` = from the beginning) | moved past, like a Kafka consumer without `breakOnFirstError` | | `BLPOP` / `BRPOP` | polls `LPOP` / `RPOP` every `pollDelayMs` (a blocking pop would hold the connection the whole process shares) | lost (at-most-once) | | the same with `processingList` | `LMOVE` into that list, removed after the route succeeded | back to the head of the queue and processed again; what a previous run left there is returned at start. One consumer per processing list | `streamClaimMinIdleMs` must exceed the longest time a route takes: a slower route would have its entry claimed by another consumer while it still works on it. A consumer is ready when its route has started: the subscription, the consumer group and the XREAD position are set up before `Start()` returns, so a message published right after the start is received. A Redis that does not answer at start fails the route start with an error naming the consumer (`redis:SUBSCRIBE:orders cannot start ...`); an outage after the start is ridden out by the client, which reconnects and subscribes again. ### Stream batch mode `batching=true` on an `XREAD` or `XGROUP` consumer hands the route one exchange per batch of entries, by the batch contract every broker of redb.Route follows. Apache Camel's Redis component has no batch consumer; the contract is redb.Route's own, the same as for Kafka, RabbitMQ, IBM MQ, SQS, AMQP 1.0 and Service Bus. - `maxBatchMessages` caps the batch (default `streamReadCount`); `pollTimeoutMs` (default 1000) sends a batch on once no entry came for that long, restarted by every entry; `batchingIntervalMs` sends it on once that long has passed since its first entry. Each read asks for at most `streamReadCount` entries. A batch option without `batching=true`, a value out of range, and `batching=true` on Pub/Sub or a list consumer (nothing there acknowledges a batch) fail the start. - The body is a `List`, one message per entry with the same body (its fields) and headers a single entry gets, even for a batch of one; `redbRedis.Stream` is set on the batch message. The exchange is InOnly. - With a group, every entry is acknowledged in one `XACK` after the route. A failed batch follows the rule of a failed entry for every entry in it: it stays pending, and `streamClaimMinIdleMs` claims it again; the claimed entries are taken into a batch before new ones. `streamClaimMinIdleMs` must exceed the time a batch takes from its first entry to the end of its route. With `ackMode=auto` the entries are read with `NOACK`. - Without a group the consumer's position moves past every entry it reads, a failed batch included, as in single mode. - A batch half collected when the consumer stops is not run; with a group its entries stay pending. ## Transactions Redis is a store first, so inside a route's `.Transacted()` block only the operations that announce work wait for the commit: - **`PUBLISH` and `XADD`** follow the block like a broker send: they run once the database has committed and are dropped if the block rolls back. The entry id (`redbRedis.Stream.MessageId`) and the recipient count reach the exchange headers after the commit. `.Transacted(false)` runs them at once. - **Other writes** (`SET`, `INCR`, `SETNX`, lists, hashes, sets) run at once: they exist for their effect and their result right now. `.Transacted()` holds one back until the commit; the route then does not get its result. - **Reads and pops** (`GET`, `LPOP` and the like) exist for what they return and refuse `.Transacted()` when the route starts. A deferred operation is the same operation, run after the commit on a snapshot of the exchange taken at the step: the same key, body, fields, headers and TTL. Outside a block, `.Transacted()` fails the step instead of losing the write. ## Part of [redb.Route](../README.md) — ESB & EIP Framework for .NET ## Named connection factory Keep credentials out of the route URI: register a factory in the context registry and reference it by name. A set-but-unknown name fails loud at startup — a typo can never silently fall back to inline URI parameters. ```csharp context.AddToRegistry("prod", new RedisConnectionFactory { ConnectionString = "redis.internal:6379", Password = secrets.RedisPassword, }); // redis:GET:cache?connectionFactory=prod ``` ## Tracing On the `redb.Route` activity source (`AddSource("redb.Route")`), with `redb.route.endpoint`: - **Consumer.** One `Consumer` span, `redis {operation} receive`, per routed pub/sub message, stream entry or list item, with `messaging.system` = `redis` and the channel, stream or list as `messaging.destination.name`. A Redis value carries no trace context (a stream entry's fields are its body), so the span is a root, never a child of the activity the consumer loop inherited from whoever started the routes; nothing arriving opens none. A failed route marks it an error; our own stop does not. - **Producer.** One `Client` span per command, `redis {operation}`, with `db.system` = `redis`; an error when the command fails, unless our own token cancelled it. - `RouteEngineOptions.EnableTelemetry = false` opens neither span.