Skip to main content

redis_tower_modules/
lib.rs

1//! High-level, ergonomic client interfaces for Redis Stack modules.
2//!
3//! This crate is the dedicated home for typed, ergonomic clients over the
4//! Redis Stack modules (RedisJSON, RediSearch, RedisTimeSeries, the
5//! probabilistic data structures, and Vector Sets). Callers never see raw
6//! [`Frame`](redis_tower::Frame) values or command structs; they work with
7//! typed Rust values, with serialization and response parsing handled inside
8//! each client.
9//!
10//! The lower-level command builders live in `redis-tower-commands`, and the
11//! `redis-tower` crate exposes the connections and middleware these clients
12//! wrap. This crate sits on top, trading a little flexibility for a much
13//! friendlier surface.
14//!
15//! # Feature flags
16//!
17//! Each module client is gated behind a feature flag. The `full` feature
18//! (enabled by default) turns them all on.
19//!
20//! | Feature         | Enables                                                        |
21//! |-----------------|----------------------------------------------------------------|
22//! | `json`          | [`json::JsonClient`] — RedisJSON                               |
23//! | `search`        | [`search::SearchClient`] — RediSearch                          |
24//! | `timeseries`    | [`timeseries::TimeSeriesClient`] — RedisTimeSeries             |
25//! | `probabilistic` | Bloom, Cuckoo, Count-Min Sketch, TopK, T-Digest clients        |
26//! | `vector`        | [`vector::VectorSetClient`] — Vector Sets                      |
27//! | `full`          | All of the above (default)                                     |
28//!
29//! # Quick start
30//!
31//! ```no_run
32//! use redis_tower::RedisClient;
33//! use redis_tower_modules::json::JsonClient;
34//! use serde::{Deserialize, Serialize};
35//!
36//! #[derive(Serialize, Deserialize)]
37//! struct User {
38//!     name: String,
39//!     age: u32,
40//! }
41//!
42//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
43//! let client = RedisClient::connect_url("redis://127.0.0.1:6379").await?;
44//! let mut json = JsonClient::new(client);
45//!
46//! let user = User { name: "Ada".into(), age: 36 };
47//! json.set("user:1", "$", &user).await?;
48//!
49//! let fetched: Option<User> = json.get("user:1", "$").await?;
50//! assert_eq!(fetched.expect("user:1 was just written").name, "Ada");
51//! # Ok(())
52//! # }
53//! ```
54//!
55//! # Binary data
56//!
57//! Module keys, Bloom/Cuckoo/sketch items, Search suggestions and payloads,
58//! TimeSeries labels, and Vector Set elements accept binary-safe
59//! [`CommandArg`](redis_tower::commands::CommandArg) inputs. Corresponding
60//! opaque response positions use [`bytes::Bytes`]. JSONPath, serialized JSON,
61//! Search query/schema syntax, timestamps, and Vector Set filter expressions
62//! remain structured text or numeric inputs.
63
64#![forbid(unsafe_code)]
65#![deny(missing_docs)]
66#![cfg_attr(docsrs, feature(doc_cfg))]
67
68#[cfg(feature = "json")]
69#[cfg_attr(docsrs, doc(cfg(feature = "json")))]
70pub mod json;
71
72#[cfg(feature = "search")]
73#[cfg_attr(docsrs, doc(cfg(feature = "search")))]
74pub mod search;
75
76#[cfg(feature = "timeseries")]
77#[cfg_attr(docsrs, doc(cfg(feature = "timeseries")))]
78pub mod timeseries;
79
80#[cfg(feature = "probabilistic")]
81#[cfg_attr(docsrs, doc(cfg(feature = "probabilistic")))]
82pub mod probabilistic;
83
84#[cfg(feature = "vector")]
85#[cfg_attr(docsrs, doc(cfg(feature = "vector")))]
86pub mod vector;