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
//! Redis Enterprise REST API client
//!
//! A comprehensive Rust client library for the Redis Enterprise REST API, providing
//! full cluster management, database operations, security configuration, and monitoring
//! capabilities. This crate offers both typed and untyped API access with comprehensive
//! coverage of all Enterprise REST endpoints.
//!
//! # Features
//!
//! - **Complete API Coverage**: Full coverage of v1 endpoints plus select v2
//! endpoints where they exist (e.g., actions, modules)
//! - **Type-Safe Operations**: Strongly typed request/response models
//! - **Flexible Authentication**: Basic auth with optional SSL verification
//! - **Async/Await Support**: Built on Tokio for high-performance async operations
//! - **Error Handling**: Comprehensive error types with context
//! - **Builder Patterns**: Ergonomic API for complex request construction
//! - **Versioned APIs**: Clear accessors for v1 and v2 where both exist
//!
//! # Quick Start
//!
//! Add to your `Cargo.toml`:
//! ```toml
//! [dependencies]
//! redis-enterprise = "0.7"
//! tokio = { version = "1", features = ["full"] }
//! ```
//!
//! # Environment Variables
//!
//! The client supports configuration via environment variables:
//! - `REDIS_ENTERPRISE_URL`: Base URL for the cluster (e.g., `https://cluster:9443`)
//! - `REDIS_ENTERPRISE_USER`: Username for authentication
//! - `REDIS_ENTERPRISE_PASSWORD`: Password for authentication
//! - `REDIS_ENTERPRISE_INSECURE`: Set to `true` to skip SSL verification (dev only)
//!
//! # Module Organization
//!
//! The library is organized into domain-specific modules:
//!
//! - **Core Resources**: [`bdb`], [`cluster`], [`nodes`], [`users`], [`roles`]
//! - **Monitoring**: [`stats`], [`alerts`], [`logs`], [`diagnostics`]
//! - **Advanced**: [`crdb`], [`shards`], [`proxies`], [`redis_acls`]
//! - **Configuration**: [`services`], [`cm_settings`], [`suffixes`]
//!
//! # Return Types
//!
//! Most methods return strongly-typed structs. Methods returning `serde_json::Value`:
//! - **Stats/Metrics**: Dynamic keys based on metric names
//! - **Legacy endpoints**: `start()`, `stop()` - use typed action methods instead
//! - **Variable schemas**: Endpoints with version-dependent responses
//! - **Passthrough access**: For direct API access via the CLI
//!
//! # Examples
//!
//! ## Creating a Client
//!
//! ```no_run
//! use redis_enterprise::EnterpriseClient;
//!
//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // From environment variables
//! let client = EnterpriseClient::from_env()?;
//!
//! // Or using the builder
//! let client = EnterpriseClient::builder()
//! .base_url("https://cluster.example.com:9443")
//! .username("admin@example.com")
//! .password("password")
//! .insecure(false)
//! .build()?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Working with Databases
//!
//! ```no_run
//! use redis_enterprise::{EnterpriseClient, CreateDatabaseRequest};
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // List all databases using fluent API
//! let databases = client.databases().list().await?;
//! for db in databases {
//! println!("Database: {} ({})", db.name, db.uid);
//! }
//!
//! // Create a new database
//! let request = CreateDatabaseRequest::builder()
//! .name("my-database")
//! .memory_size(1024 * 1024 * 1024) // 1GB
//! .port(12000)
//! .replication(false)
//! .persistence("aof")
//! .build();
//!
//! let new_db = client.databases().create(request).await?;
//! println!("Created database: {}", new_db.uid);
//!
//! // Get database stats
//! let stats = client.databases().stats(new_db.uid).await?;
//! println!("Ops/sec: {:?}", stats);
//! # Ok(())
//! # }
//! ```
//!
//! ## Managing Nodes
//!
//! ```no_run
//! use redis_enterprise::EnterpriseClient;
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // List all nodes in the cluster
//! let nodes = client.nodes().list().await?;
//! for node in nodes {
//! println!("Node {}: {:?} ({})", node.uid, node.addr, node.status);
//! }
//!
//! // Get detailed node information
//! let node_info = client.nodes().get(1).await?;
//! println!("Node memory: {:?} bytes", node_info.total_memory);
//!
//! // Check node stats
//! let stats = client.nodes().stats(1).await?;
//! println!("CPU usage: {:?}", stats);
//! # Ok(())
//! # }
//! ```
//!
//! ## Cluster Operations
//!
//! ```no_run
//! use redis_enterprise::EnterpriseClient;
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // Get cluster information
//! let cluster_info = client.cluster().info().await?;
//! println!("Cluster name: {}", cluster_info.name);
//! println!("Nodes: {:?}", cluster_info.nodes);
//!
//! // Get cluster statistics
//! let stats = client.cluster().stats().await?;
//! println!("Total memory: {:?}", stats);
//!
//! // Check license status
//! let license = client.cluster().license().await?;
//! println!("License expires: {:?}", license);
//! # Ok(())
//! # }
//! ```
//!
//! ## Versioned Endpoints (v1/v2)
//!
//! Some Enterprise endpoints have both v1 and v2 flavors. Use versioned sub-handlers
//! to make intent explicit and keep models clean.
//!
//! ```no_run
//! use redis_enterprise::EnterpriseClient;
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // Actions: v1 and v2
//! let v1_actions = client.actions().v1().list().await?; // GET /v1/actions
//! let v2_actions = client.actions().v2().list().await?; // GET /v2/actions
//!
//! // Modules
//! let all = client.modules().list().await?; // GET /v1/modules
//! // Upload uses v2 endpoint with fallback to v1
//! let uploaded = client.modules().upload(b"module_data".to_vec(), "module.zip").await?;
//! # Ok(())
//! # }
//! ```
//!
//! # Typed-Only Client
//!
//! The Enterprise client exposes typed request/response APIs by default. Raw JSON
//! passthroughs are avoided except for intentionally opaque operations (for example,
//! database command passthrough or module uploads). This keeps CLI and library usage
//! consistent and safer while maintaining flexibility where the wire format is open.
//!
//! ## User Management
//!
//! ```no_run
//! use redis_enterprise::{EnterpriseClient, CreateUserRequest};
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // List all users
//! let users = client.users().list().await?;
//! for user in users {
//! println!("User: {} ({})", user.email, user.role);
//! }
//!
//! // Create a new user
//! let request = CreateUserRequest::builder()
//! .email("newuser@example.com")
//! .password("secure_password")
//! .role("db_member")
//! .name("New User")
//! .email_alerts(true)
//! .build();
//!
//! let new_user = client.users().create(request).await?;
//! println!("Created user: {}", new_user.uid);
//! # Ok(())
//! # }
//! ```
//!
//! ## Monitoring and Alerts
//!
//! ```no_run
//! use redis_enterprise::EnterpriseClient;
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // Check active alerts
//! let alerts = client.alerts().list().await?;
//! for alert in alerts {
//! println!("Alert: {} - {}", alert.name, alert.severity);
//! }
//!
//! // Get cluster statistics
//! let cluster_stats = client.stats().cluster(None).await?;
//! println!("Cluster stats: {:?}", cluster_stats);
//! # Ok(())
//! # }
//! ```
//!
//! ## Active-Active Databases (CRDB)
//!
//! ```no_run
//! use redis_enterprise::{EnterpriseClient, CreateCrdbRequest};
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! // List Active-Active databases
//! let crdbs = client.crdb().list().await?;
//! for crdb in crdbs {
//! println!("CRDB: {} ({})", crdb.name, crdb.guid);
//! }
//!
//! // Create an Active-Active database
//! let request = CreateCrdbRequest {
//! name: "global-cache".to_string(),
//! memory_size: 1024 * 1024 * 1024, // 1GB per instance
//! instances: vec![
//! // Define instances for each participating cluster
//! ],
//! encryption: Some(false),
//! data_persistence: Some("aof".to_string()),
//! eviction_policy: Some("allkeys-lru".to_string()),
//! };
//!
//! let new_crdb = client.crdb().create(request).await?;
//! println!("Created CRDB: {}", new_crdb.guid);
//! # Ok(())
//! # }
//! ```
//!
//! # Error Handling
//!
//! The library provides detailed error information for all API operations with
//! convenient error variants and helper methods:
//!
//! ```no_run
//! use redis_enterprise::{EnterpriseClient, RestError};
//!
//! # async fn example(client: EnterpriseClient) -> Result<(), Box<dyn std::error::Error>> {
//! match client.databases().get(999).await {
//! Ok(db) => println!("Found database: {}", db.name),
//! Err(RestError::NotFound) => println!("Database not found"),
//! Err(RestError::Unauthorized) => println!("Invalid credentials"),
//! Err(RestError::ServerError(msg)) => println!("Server error: {}", msg),
//! Err(e) if e.is_not_found() => println!("Not found: {}", e),
//! Err(e) => println!("Unexpected error: {}", e),
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Handler Overview
//!
//! The library exposes focused handlers per API domain, accessible via fluent methods:
//!
//! | Accessor | Purpose | Key Operations |
//! |----------|---------|----------------|
//! | `client.cluster()` | Cluster lifecycle | info, update, license, services |
//! | `client.databases()` | Databases (BDB) | list, get, create, update, delete, stats |
//! | `client.nodes()` | Node management | list, get, stats |
//! | `client.users()` | Users | list, get, create, update, delete |
//! | `client.roles()` | Roles | list, get, assign |
//! | `client.modules()` | Modules | list (v1), upload (v2) |
//! | `client.alerts()` | Alerts | list, acknowledge |
//! | `client.stats()` | Monitoring | cluster/node/database stats |
//! | `client.logs()` | Logs | cluster and database logs |
//! | `client.actions()` | Actions | v1/v2 workflows |
//! | `client.crdb()` | Active-Active | list, get, create, update |
//! | `client.shards()` | Shard management | list, get, stats |
//! | `client.proxies()` | Proxy management | list, get, stats |
//! | `client.redis_acls()` | Redis ACLs | list, get, create, update, delete |
//! | `client.bootstrap()` | Cluster bootstrap | status, create |
//! | `client.license()` | License management | get, update, usage |
//! | `client.diagnostics()` | Diagnostics | run, status |
//! | `client.debug_info()` | Debug info | collect, download |
//!
//! # Production Best Practices
//!
//! - **Connection Pooling**: The client reuses HTTP connections automatically
//! - **Timeout Configuration**: Set appropriate timeouts for your environment
//! - **SSL Verification**: Always enable in production (disable only for development)
//! - **Error Handling**: Implement retry logic for transient failures
//! - **Monitoring**: Log all API operations and track response times
//!
//! # API Coverage
//!
//! This crate provides complete coverage of the Redis Enterprise REST API:
//!
//! - **Cluster Management**: Bootstrap, configuration, licenses
//! - **Database Operations**: CRUD, backup/restore, configuration
//! - **Security**: Users, roles, ACLs, LDAP integration
//! - **Monitoring**: Stats, alerts, logs, diagnostics
//! - **High Availability**: Active-Active (CRDB), replication
//! - **Modules**: Redis module management
//! - **Maintenance**: Upgrades, migrations, debug info
// Core client and error types
pub use ;
pub use ;
// Re-export Tower integration when feature is enabled
pub use tower_support;
// Testing utilities for consumers
// Database management
pub use ;
// Database groups
pub use ;
// Cluster management
pub use ;
// Node management
pub use ;
// User management
pub use ;
// Module management
pub use ;
// Action tracking
pub use ;
// Logs
pub use ;
// Active-Active databases
pub use ;
// Statistics
pub use ;
// Alerts
pub use ;
// Redis ACLs
pub use ;
// Shards
pub use ;
// Proxies
pub use ;
// LDAP mappings
pub use ;
// OCSP
pub use ;
// Local endpoints
pub use LocalHandler;
// Bootstrap
pub use ;
// Cluster Manager settings
pub use ;
// CRDB tasks
pub use ;
// Debug info
pub use ;
// Diagnostics
pub use ;
// Endpoints
pub use ;
// Job scheduler
pub use ;
// JSON Schema
pub use JsonSchemaHandler;
// License
pub use ;
// Migrations
pub use ;
// Roles
pub use ;
// Services
pub use ;
// Suffixes
pub use ;
// Usage report
pub use ;