Path: redb-route/redb.Route.Redis/RedisEndpointOptions.cs
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/RedisEndpointOptions.cs
----
using redb.Route.Batching;
using redb.Route.Core;
namespace redb.Route.Redis;
///
/// Typed options for . Bound from URI query parameters.
///
public sealed class RedisEndpointOptions : EndpointOptions
{
// ── Connection ──
/// Redis connection string (default: localhost:6379).
[Sensitive]
public string ConnectionString { get; set; } = "localhost:6379";
/// Redis database index (default: 0).
public int Database { get; set; }
/// Redis password (optional).
[Sensitive]
public string? Password { get; set; }
/// Name of in the route registry.
[RegistryReference(typeof(RedisConnectionFactory))]
public string? ConnectionFactory { get; set; }
// ── Operation parameters ──
/// Redis key (for key-based operations). May contain dynamic expressions.
public string? Key { get; set; }
/// Channel name for Pub/Sub operations.
public string? Channel { get; set; }
/// Stream name for Redis Streams.
public string? StreamName { get; set; }
/// Consumer group for Streams.
public string? ConsumerGroup { get; set; }
/// Consumer name within a group.
public string? ConsumerName { get; set; }
/// Redis command for COMMAND operation type.
public string? Command { get; set; }
///
/// Subscribe to as a pattern. PSUBSCRIBE always does; this makes SUBSCRIBE do it too.
///
public bool UsePattern { get; set; }
// ── TTL and score ──
/// Time-to-live in seconds for SET/EXPIRE. 0 = no expiry.
public int Ttl { get; set; }
/// Score for sorted set operations.
public double? Score { get; set; }
/// Hash field name for HSET/HGET operations.
public string? Field { get; set; }
// ── Range ──
/// Range start for LRANGE/ZRANGE operations.
public long? Start { get; set; }
/// Range stop for LRANGE/ZRANGE operations.
public long? Stop { get; set; }
/// Min score for ZRANGEBYSCORE.
public double? MinScore { get; set; }
/// Max score for ZRANGEBYSCORE.
public double? MaxScore { get; set; }
// ── Geospatial ──
/// Longitude for GEOADD/GEORADIUS.
public double? Longitude { get; set; }
/// Latitude for GEOADD/GEORADIUS.
public double? Latitude { get; set; }
/// First member for GEODIST.
public string? Member1 { get; set; }
/// Second member for GEODIST.
public string? Member2 { get; set; }
/// Unit for geo operations: m, km, mi, ft (default: m).
public string GeoUnit { get; set; } = "m";
// ── Bitmap ──
/// Bit offset for SETBIT/GETBIT.
public long? Offset { get; set; }
/// Bit value for SETBIT.
public bool? Bit { get; set; }
// ── Streams ──
/// Max stream length for XADD (0 = unlimited).
public int StreamMaxLength { get; set; }
/// Use approximate max length for XADD trimming.
public bool StreamApproximate { get; set; } = true;
/// Number of entries to read at a time from a stream.
public int StreamReadCount { get; set; } = 10;
/// Block time in ms when no stream entries available.
public int StreamBlockTimeMs { get; set; } = 1000;
///
/// When a stream entry read through a consumer group is settled (). Manual
/// (default): acknowledged (XACK) after its route succeeded; a failed one stays pending (at-least-once).
/// Auto: read with NOACK, it counts as delivered when it is read and never enters the group's pending list,
/// so an entry whose route failed is not read again (at-most-once).
///
public AckMode AckMode { get; set; } = AckMode.Manual;
///
/// Where a stream consumer starts. Unset: at the entries added from now on — for a group, the group is created at the
/// stream's end; without one, the consumer pins the stream's last entry when it starts. 0 reads from the
/// beginning, an entry id after that entry. > only means something to a group and is refused without one.
///
public string? StreamStartPosition { get; set; }
///
/// A group consumer claims (XAUTOCLAIM) entries of its group that have stayed pending for at least this many
/// milliseconds — a failed entry of its own, or one a consumer that died left behind — and processes them again.
/// Unset: pending entries are not claimed. Must exceed the longest time a route takes: a slower one would have its
/// entry claimed while it still works on it. Not with ackMode=auto, which leaves nothing pending.
///
public int? StreamClaimMinIdleMs { get; set; }
// ── Streams: batch mode ──
///
/// Batch mode of a stream consumer (Apache Camel batching, the batch contract of every broker of redb.Route):
/// the route gets one InOnly exchange whose body is a List<IMessage> of up to
/// entries, settled once after the route: with a consumer group acknowledged in one
/// XACK on success, left pending on failure, as a failed single entry is. XREAD/XGROUP only.
///
public bool Batching { get; set; }
/// Largest number of entries in a batch (default ).
public int? MaxBatchMessages { get; set; }
///
/// Batch mode: a batch with entries is sent on once no entry came for this many milliseconds, restarted by every
/// entry (default 1000).
///
public int PollTimeoutMs { get; set; } = 1000;
/// Batch mode: a batch is sent on once this many milliseconds have passed since its first entry.
public int? BatchingIntervalMs { get; set; }
/// The batch options, or null outside batch mode. Set by .
internal BatchOptions? Batch { get; private set; }
///
/// Resolves the batch options. Fails, naming the endpoint, where batch mode cannot work: a batch option without
/// batching=true, a value out of range, and an operation other than XREAD/XGROUP: pub/sub and lists have no
/// acknowledgement a batch could be settled by.
///
internal void ResolveBatch(string endpoint, RedisOperationType operation)
{
Batch = BatchOptions.Resolve(endpoint, Batching, MaxBatchMessages, PollTimeoutMs, BatchingIntervalMs, StreamReadCount);
if (Batch is not null && operation is not (RedisOperationType.XREAD or RedisOperationType.XGROUP))
throw new InvalidOperationException(
$"Endpoint '{endpoint}': batching=true needs a stream consumer (XREAD or XGROUP); {operation} has no " +
"acknowledgement a batch could be settled by.");
}
///
/// A BLPOP/BRPOP consumer moves an item into this list (LMOVE) instead of popping it, and removes it from there after
/// its route succeeded: a failed item goes back to the head of the queue and is processed again, and what a
/// previous run left in this list is returned to the queue when the consumer starts (at-least-once). Unset: the item
/// is popped and a failed one is gone (at-most-once). One consumer per processing list.
///
public string? ProcessingList { get; set; }
// ── Transactions ──
///
/// Producer: whether the operation waits for the commit of the enclosing .Transacted() block. PUBLISH and XADD
/// announce work and follow the block when unset: deferred inside one, at once outside; false sends at once even
/// inside one. Every other write runs at once unless true defers it; true requires a block and is refused
/// at start for an operation that exists for what it returns (GET, LPOP and the other reads).
///
public bool? Transacted { get; set; }
// ── Resilience ──
/// Polling delay in ms when list/stream consumer finds no messages.
public int PollDelayMs { get; set; } = 1000;
///
public override void Validate()
{
if (StreamReadCount <= 0)
throw new ArgumentOutOfRangeException(nameof(StreamReadCount), "StreamReadCount must be > 0.");
if (StreamClaimMinIdleMs is <= 0)
throw new ArgumentOutOfRangeException(nameof(StreamClaimMinIdleMs), "StreamClaimMinIdleMs must be > 0.");
if (StreamClaimMinIdleMs is not null && AckMode == AckMode.Auto)
throw new ArgumentException(
"'streamClaimMinIdleMs' claims pending entries, and 'ackMode=auto' leaves none: they contradict each other.");
if (ProcessingList is not null && string.IsNullOrWhiteSpace(ProcessingList))
throw new ArgumentException("'processingList' is empty: name the list, or leave it unset.");
}
///
protected override string? UnknownParameterHint(string name)
=> name.Equals("streamNoAck", StringComparison.OrdinalIgnoreCase)
? "'streamNoAck' is replaced by 'ackMode': ackMode=auto reads with NOACK, as streamNoAck=true did; " +
"ackMode=manual (the default) acknowledges after the route."
: name.Equals("streamAutoAck", StringComparison.OrdinalIgnoreCase)
? "'streamAutoAck' is gone: 'streamAutoAck=false' read with NOACK while its name promised a manual " +
"acknowledgement. A group consumer acknowledges after its route succeeded; 'ackMode=auto' reads " +
"with NOACK (at-most-once)."
: null;
}