redis-tower-modules 0.1.3

High-level ergonomic client interfaces for Redis Stack modules
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
# redis-tower

[![Crates.io](https://img.shields.io/crates/v/redis-tower.svg)](https://crates.io/crates/redis-tower)
[![Documentation](https://docs.rs/redis-tower/badge.svg)](https://docs.rs/redis-tower)
[![CI](https://github.com/joshrotenberg/redis-tower/actions/workflows/ci.yml/badge.svg)](https://github.com/joshrotenberg/redis-tower/actions/workflows/ci.yml)
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/redis-tower.svg)](https://github.com/joshrotenberg/redis-tower#license)

A typed, async Redis client built around Tower services.

- Typed commands and responses for Redis 7.x, Redis 8.x, and Redis Stack.
- A cloneable, auto-pipelined client for normal application traffic.
- Standalone, Cluster, Sentinel, blocking, and topology-neutral clients.
- Tower middleware, reconnection, pooling, client-side caching, metrics, TLS,
  and rotating credentials.

## Install

```bash
cargo add redis-tower
```

The default feature set includes the Redis Stack command builders. A smaller
core-only dependency looks like this:

```toml
[dependencies]
redis-tower = { version = "0.1", default-features = false }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
```

Add the topology or higher-level crates only when you need them:

```bash
cargo add redis-tower-cluster redis-tower-sentinel redis-tower-client
cargo add redis-tower-modules redis-tower-primitives redis-tower-sync
```

The minimum supported Rust version is 1.88.

## Quick start

[`MultiplexedClient`](https://docs.rs/redis-tower/latest/redis_tower/struct.MultiplexedClient.html)
is the recommended default. It is cheap to clone, accepts concurrent commands,
and automatically pipelines work over one connection.

```rust
use redis_tower::{MultiplexedClient, RedisValueExt};
use redis_tower::commands::{Get, Set};

# async fn example() -> Result<(), Box<dyn std::error::Error>> {
let client = MultiplexedClient::connect("127.0.0.1:6379").await?;

client.execute(Set::new("greeting", "hello")).await?;
let greeting: String = client
    .execute(Get::new("greeting"))
    .await?
    .parse_into()?;

assert_eq!(greeting, "hello");
# Ok(())
# }
```

Redis URLs support authentication, database selection, Unix sockets, and TLS:

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
# use redis_tower::MultiplexedClient;
let client = MultiplexedClient::connect_url(
    "rediss://default:secret@redis.example.com:6380/0",
).await?;
# let _ = client;
# Ok(())
# }
```

Unix URLs use the redis-rs-compatible query form. Socket paths are
percent-decoded, and the `redis+unix` and `valkey+unix` aliases are accepted:

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
# use redis_tower::MultiplexedClient;
let client = MultiplexedClient::connect_url(
    "redis+unix:///run/redis%20server.sock?user=app&pass=secret&db=1&protocol=resp3",
).await?;
# let _ = client;
# Ok(())
# }
```

## Choose a client

| Client | Use it for |
|---|---|
| `MultiplexedClient` | Most async applications; cloneable and auto-pipelined |
| `CachedMultiplexedClient` | Read-heavy standalone workloads using RESP3 client-side caching |
| `RedisConnection` | Exclusive access to one connection or custom Tower stacks |
| `RedisClient` | Simple serialized sharing behind a mutex |
| `ResilientRedisClient` | Automatic reconnect with optional bounded offline queuing |
| `ConnectionPool` | Blocking commands, multiple sockets, or CPU-heavy response parsing |
| `MultiplexedClusterClient` | High-concurrency Redis Cluster workloads |
| `MultiplexedSentinelClient` | Sentinel discovery, failover, and replica reads |
| `UniversalClient` | One application type selected by standalone, Cluster, or Sentinel URL |
| `SyncClient` | CLI tools and other blocking code |

The [production tuning guide](https://github.com/joshrotenberg/redis-tower/blob/main/docs/PRODUCTION-TUNING.md)
goes deeper on client selection, backpressure, timeouts, pooling, reconnects,
and shutdown.

## Common operations

Commands are ordinary typed values. Optional arguments use builder methods.

```rust
use redis_tower::commands::{Set, XAdd, ZAdd};

let set = Set::new("session:42", "active").ex(60).nx();
let score = ZAdd::new("leaders").member(100.0, "alice");
let event = XAdd::new("events").field("kind", "created");
# let _ = (set, score, event);
```

Pipelines batch a known group of commands. Transactions use Redis
`WATCH`/`MULTI`/`EXEC` semantics.

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
# use redis_tower::{Pipeline, RedisConnection, Transaction};
# use redis_tower::commands::{Get, Incr, Set};
# let mut conn = RedisConnection::connect("127.0.0.1:6379").await?;
let results = Pipeline::new()
    .push(Set::new("a", "1"))
    .push(Incr::new("counter"))
    .push(Get::new("a"))
    .execute(&mut conn)
    .await?;

let transaction = Transaction::new()
    .watch(["counter"])
    .push(Incr::new("counter"))
    .execute(&mut conn)
    .await?;
# let _ = (results, transaction);
# Ok(())
# }
```

## Deployment topologies

For binary channel or pattern names, use `BinaryPubSubConnection` and the
`subscribe_bytes` / `psubscribe_bytes` / `ssubscribe_bytes` methods. Messages
and tracked subscriptions retain `Bytes`, including across reconnects. Cluster
clients expose `pubsub_on_bytes` and `sharded_pubsub_bytes` with the same
routing and recovery behavior as the text API.

RESP3 attribute-prefixed replies currently fail with a protocol error. The
transport closes rather than assign an attribute or its payload to the wrong
pipelined request. Complete attribute metadata support needs a response model
that pairs the prefix with its following value.

### Cluster

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use redis_tower::commands::{Get, Set};
use redis_tower_cluster::{MultiplexedClusterClient, ReadPreference};

let client = MultiplexedClusterClient::builder("127.0.0.1:7000")
    .read_preference(ReadPreference::PreferReplica)
    .connect()
    .await?;

client.execute(Set::new("{user:42}:name", "Ada")).await?;
let name = client.execute(Get::new("{user:42}:name")).await?;
# let _ = name;
# Ok(())
# }
```

Raw `FT.CURSOR` and counted set/cardinality commands route by the index or
first declared key, including binary keys and hash tags.

For node-local or connection-stateful work, `client.connect_to_node(node)`
opens an exclusively owned connection to a current topology member using the
client's authentication, TLS, protocol, and connection timeout settings. The
caller bounds command duration and owns the socket; shared workers remain
available. This connection does not route commands or replay failures.

The Cluster crate also provides explicit cross-node pipelines, split multi-key
helpers, cluster-wide scans, regular and sharded Pub/Sub, replica routing, and
automatic MOVED/ASK handling.

### Sentinel

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use redis_tower::commands::Ping;
use redis_tower_sentinel::{MultiplexedSentinelClient, ReadPreference};

let client = MultiplexedSentinelClient::builder(
    &["127.0.0.1:26379", "127.0.0.1:26380"],
    "mymaster",
)
.read_preference(ReadPreference::PreferReplica)
.connect()
.await?;

client.execute(Ping::new()).await?;
# Ok(())
# }
```

### One client for every topology

`redis-tower-client` chooses a variant from the URL scheme:

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use redis_tower::commands::Ping;
use redis_tower_client::UniversalClient;

let standalone = UniversalClient::connect_url("redis://127.0.0.1:6379").await?;
let cluster = UniversalClient::connect_url("redis+cluster://127.0.0.1:7000").await?;
let sentinel = UniversalClient::connect_url(
    "redis+sentinel://127.0.0.1:26379/mymaster",
).await?;

standalone.execute(Ping::new()).await?;
# let _ = (cluster, sentinel);
# Ok(())
# }
```

Use the `rediss`, `rediss+cluster`, and `rediss+sentinel` variants for TLS.

## Data access modules

The `redis-tower-modules` crate provides higher-level clients over the lower-
level typed command builders.

| Module | Client | Typical use |
|---|---|---|
| RedisJSON | `json::JsonClient` | Serialize application types with Serde |
| RediSearch | `search::SearchClient` | Define indexes and deserialize query results |
| RedisTimeSeries | `timeseries::TimeSeriesClient` | Store and query timestamped samples |
| Probabilistic | `probabilistic::*` | Bloom, Cuckoo, CMS, TopK, and T-Digest |
| Vector Sets | `vector::VectorSetClient` | Add vectors and run similarity search |

### JSON

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use redis_tower::MultiplexedClient;
use redis_tower_modules::json::JsonClient;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct User { name: String }

let client = MultiplexedClient::connect("127.0.0.1:6379").await?;
let mut json = JsonClient::new(client);
json.set("user:42", "$", &User { name: "Ada".into() }).await?;
let user: Option<User> = json.get("user:42", "$").await?;
# let _ = user;
# Ok(())
# }
```

### Search, time series, probabilistic structures, and vectors

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use redis_tower::RedisConnection;
use redis_tower_modules::probabilistic::BloomFilter;
use redis_tower_modules::search::{IndexBuilder, SearchClient};
use redis_tower_modules::timeseries::{TimeSeriesClient, TsKeyConfig, TsTimestamp};
use redis_tower_modules::vector::VectorSetClient;

let mut conn = RedisConnection::connect("127.0.0.1:6379").await?;

SearchClient::new(&mut conn)
    .create_index(IndexBuilder::new("users").on_hash().text_field("name"))
    .await?;

TimeSeriesClient::new(&mut conn)
    .create("temperature", TsKeyConfig::new().label("room", "lab"))
    .await?;
TimeSeriesClient::new(&mut conn)
    .add("temperature", TsTimestamp::Auto, 21.5)
    .await?;

{
    let mut bloom = BloomFilter::new(&mut conn, "seen-users");
    bloom.add("user:42").await?;
}

let mut vectors = VectorSetClient::new(&mut conn, "embeddings");
vectors.add(vec![1.0, 0.0, 0.0], "user:42").await?;
# Ok(())
# }
```

## Pub/Sub, streams, and caching

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
# use redis_tower::RedisConnection;
let conn = RedisConnection::connect("127.0.0.1:6379").await?;
let mut pubsub = redis_tower::PubSubConnection::from_connection(conn)?;
pubsub.subscribe(&["events"]).await?;

while let Some(message) = pubsub.next().await {
    println!("{:?}", message?);
}
# Ok(())
# }
```

For durable processing, use Redis Streams through the typed `X*` commands or
[`StreamConsumer`](https://docs.rs/redis-tower/latest/redis_tower/struct.StreamConsumer.html).

RESP3 client-side caching is available as a managed client:

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use std::time::Duration;
use redis_tower::{CachedClientConfig, CachedMultiplexedClient};
use redis_tower::commands::Get;

let config = CachedClientConfig::new()
    .max_entries(10_000)
    .client_ttl(Some(Duration::from_secs(30)));
let client = CachedMultiplexedClient::connect_with_config(
    "127.0.0.1:6379",
    config,
).await?;

let value = client.execute(Get::new("user:42")).await?;
# let _ = value;
# Ok(())
# }
```

Read the [client-side caching guide](https://github.com/joshrotenberg/redis-tower/blob/main/docs/CLIENT-SIDE-CACHING.md)
for invalidation, failure, and consistency semantics.

## Tower middleware

`FrameService` is a `tower::Service<Frame>`. `CommandAdapter` converts a frame
stack back into a typed command service.

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use redis_tower::{CommandAdapter, FrameService, TracingLayer};
use tower::ServiceBuilder;

let service = ServiceBuilder::new()
    .layer(TracingLayer::new())
    .service(FrameService::connect("127.0.0.1:6379").await?);
let typed = CommandAdapter::new(service);
# let _ = typed;
# Ok(())
# }
```

The facade also includes request deadlines, Redis-aware retries and circuit
breaking, reconnection, cache middleware, and metrics-facade integration.

## Distributed primitives

`redis-tower-primitives` builds coordination tools on the same typed executor:

- Fenced distributed locks and leader election.
- Expirable semaphores and countdown latches.
- Delayed queues and block-allocated IDs.
- Redis-time GCRA rate limiting.

```rust
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
use std::time::Duration;
use redis_tower::MultiplexedClient;
use redis_tower_primitives::DistributedLock;

let mut client = MultiplexedClient::connect("127.0.0.1:6379").await?;
let lock = DistributedLock::new(
    "{invoice:42}:lock",
    "{invoice:42}:fence",
    Duration::from_secs(10),
)?;

if let Some(lease) = lock.acquire(&mut client).await? {
    let fencing_token = lease.fencing_token();
    // Pass fencing_token to the guarded resource and reject stale writers.
    lease.release(&mut client).await?;
}
# Ok(())
# }
```

These are Redis-backed leases, not consensus primitives. Read the
[distributed primitives guide](https://github.com/joshrotenberg/redis-tower/blob/main/docs/PRIMITIVES.md)
before using them for correctness-sensitive work.

## Authentication, TLS, and blocking code

Static credentials can be supplied through URLs or builders. Dynamic
credentials implement `CredentialProvider`; companion crates provide AWS
ElastiCache IAM and Microsoft Entra ID integrations:

- `redis-tower-auth-aws`
- `redis-tower-auth-azure`

The [cloud authentication guide](https://github.com/joshrotenberg/redis-tower/blob/main/docs/CLOUD-AUTH.md)
covers URL-backed provider factories, setup deadlines, shared provider caches,
reconnect-time refresh, and the reconnect/replay rules for dedicated Pub/Sub,
MONITOR, blocking, and transactional sessions.

Blocking applications can use `redis-tower-sync`:

```rust
use redis_tower_sync::SyncClient;
use redis_tower_sync::commands::{Get, Set};

# fn example() -> Result<(), Box<dyn std::error::Error>> {
let client = SyncClient::connect("127.0.0.1:6379")?;
client.execute(Set::new("key", "value"))?;
let value = client.execute(Get::new("key"))?;
# let _ = value;
# Ok(())
# }
```

## Workspace crates

| Crate | Purpose |
|---|---|
| `redis-tower` | Main client facade, middleware, pooling, caching, and resilience |
| `redis-tower-core` | Connection, command trait, Tower frame service, URL/TLS, conversions |
| `redis-tower-protocol` | RESP3 frames and bounded Tokio codec |
| `redis-tower-commands` | Typed Redis and Redis Stack command builders |
| `redis-tower-cluster` | Cluster topology, routing, redirects, scans, pipelines, and Pub/Sub |
| `redis-tower-sentinel` | Sentinel discovery, failover, and replica reads |
| `redis-tower-client` | Topology-neutral `UniversalClient` |
| `redis-tower-modules` | High-level JSON, Search, TimeSeries, probabilistic, and vector clients |
| `redis-tower-primitives` | Distributed coordination primitives |
| `redis-tower-sync` | Blocking wrapper |
| `redis-tower-auth-aws` | ElastiCache IAM credentials |
| `redis-tower-auth-azure` | Microsoft Entra ID credentials |
| `redis-tower-test` | Mocks and managed Redis test fixtures |

## Learn more

- [Documentation home]https://joshrotenberg.com/redis-tower/
- [Command cookbook]https://github.com/joshrotenberg/redis-tower/blob/main/docs/COMMAND-COOKBOOK.md
- [Command capability ledger]https://github.com/joshrotenberg/redis-tower/blob/main/docs/COMMAND-CAPABILITIES.md
- [Production tuning]https://github.com/joshrotenberg/redis-tower/blob/main/docs/PRODUCTION-TUNING.md
- [Serverless and scale-to-zero]https://github.com/joshrotenberg/redis-tower/blob/main/docs/SERVERLESS.md
- [Client-side caching]https://github.com/joshrotenberg/redis-tower/blob/main/docs/CLIENT-SIDE-CACHING.md
- [Cloud and rotating credentials]https://github.com/joshrotenberg/redis-tower/blob/main/docs/CLOUD-AUTH.md
- [Distributed primitives]https://github.com/joshrotenberg/redis-tower/blob/main/docs/PRIMITIVES.md
- [Migrating from redis-rs]https://github.com/joshrotenberg/redis-tower/blob/main/docs/MIGRATING-FROM-REDIS-RS.md
- [Migrating from Fred]https://github.com/joshrotenberg/redis-tower/blob/main/docs/MIGRATING-FROM-FRED.md
- [Sourced client comparison]https://github.com/joshrotenberg/redis-tower/blob/main/docs/FEATURE-MATRIX.md
- [Test conformance]https://github.com/joshrotenberg/redis-tower/blob/main/docs/TEST-CONFORMANCE.md

Runnable programs live in the
[`examples`](https://github.com/joshrotenberg/redis-tower/tree/main/examples)
directory.

## Compatibility

Redis 7.x and 8.x are the supported server lines. CI exercises Redis 7.4 and
8.0 on every change, with a broader nightly Redis and Valkey matrix. Redis
Stack command groups are feature-gated and return normal server errors when a
module is unavailable.

redis-tower is pre-1.0. A `0.x` minor release may contain breaking changes;
those changes are called out in crate changelogs.

## Security

See [SECURITY.md](https://github.com/joshrotenberg/redis-tower/blob/main/SECURITY.md)
for the vulnerability disclosure policy. The workspace forbids unsafe code and
runs dependency policy and advisory checks in CI.

## Contributing

See [CONTRIBUTING.md](https://github.com/joshrotenberg/redis-tower/blob/main/CONTRIBUTING.md)
for development setup and validation commands.

## License

Licensed under either the
[MIT License](https://github.com/joshrotenberg/redis-tower/blob/main/LICENSE-MIT)
or the
[Apache License, Version 2.0](https://github.com/joshrotenberg/redis-tower/blob/main/LICENSE-APACHE),
at your option.

The vendored Redis documentation metadata used by the repository's conformance
reports is licensed separately. See its
[license and attribution notice](https://github.com/joshrotenberg/redis-tower/blob/main/conformance/redis-8.8/NOTICE.md);
that metadata is not included in the released Rust crates.