redis_enterprise/
modules.rs

1//! Redis module management
2//!
3//! ## Overview
4//! - List available modules
5//! - Query module versions
6//! - Configure module settings
7
8use crate::client::RestClient;
9use crate::error::Result;
10use serde::{Deserialize, Serialize};
11use serde_json::Value;
12
13/// Module information
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Module {
16    pub uid: String,
17    pub module_name: Option<String>,
18    pub version: Option<u32>,
19    pub semantic_version: Option<String>,
20    pub author: Option<String>,
21    pub description: Option<String>,
22    pub homepage: Option<String>,
23    pub license: Option<String>,
24    pub command_line_args: Option<String>,
25    pub capabilities: Option<Vec<String>>,
26    pub min_redis_version: Option<String>,
27    pub compatible_redis_version: Option<String>,
28    pub display_name: Option<String>,
29    pub is_bundled: Option<bool>,
30
31    // Additional fields from API audit
32    /// Whether the module supports BigStore (Auto Tiering) version 2
33    pub bigstore_version_2_support: Option<bool>,
34
35    /// Name of the capability this module provides
36    pub capability_name: Option<String>,
37
38    /// Redis command used to configure this module
39    pub config_command: Option<String>,
40
41    /// Whether the module supports CRDB (Conflict-free Replicated Database)
42    pub crdb: Option<bool>,
43
44    /// List of other modules this module depends on
45    pub dependencies: Option<Vec<Value>>,
46
47    /// Contact email address of the module author
48    pub email: Option<String>,
49
50    /// Minimum Redis Enterprise version required for this module
51    pub min_redis_pack_version: Option<String>,
52
53    /// List of platforms this module supports (e.g., 'linux-x64', 'linux-arm64')
54    pub platforms: Option<Vec<String>>,
55
56    /// SHA256 checksum of the module binary for verification
57    pub sha256: Option<String>,
58
59    #[serde(flatten)]
60    pub extra: Value,
61}
62
63/// Module handler for managing Redis modules
64pub struct ModuleHandler {
65    client: RestClient,
66}
67
68/// Alias for backwards compatibility and intuitive plural naming
69pub type ModulesHandler = ModuleHandler;
70
71impl ModuleHandler {
72    pub fn new(client: RestClient) -> Self {
73        ModuleHandler { client }
74    }
75
76    /// List all modules
77    pub async fn list(&self) -> Result<Vec<Module>> {
78        self.client.get("/v1/modules").await
79    }
80
81    /// Get specific module
82    pub async fn get(&self, uid: &str) -> Result<Module> {
83        self.client.get(&format!("/v1/modules/{}", uid)).await
84    }
85
86    /// Upload new module (tries v2 first, falls back to v1)
87    pub async fn upload(&self, module_data: Vec<u8>, file_name: &str) -> Result<Value> {
88        // Try v2 first (returns action_uid for async tracking)
89        match self
90            .client
91            .post_multipart("/v2/modules", module_data.clone(), "module", file_name)
92            .await
93        {
94            Ok(response) => Ok(response),
95            Err(crate::error::RestError::NotFound) => {
96                // v2 endpoint doesn't exist, try v1
97                self.client
98                    .post_multipart("/v1/modules", module_data, "module", file_name)
99                    .await
100            }
101            Err(e) => Err(e),
102        }
103    }
104
105    /// Delete module
106    pub async fn delete(&self, uid: &str) -> Result<()> {
107        self.client.delete(&format!("/v1/modules/{}", uid)).await
108    }
109
110    /// Update module configuration
111    pub async fn update(&self, uid: &str, updates: Value) -> Result<Module> {
112        self.client
113            .put(&format!("/v1/modules/{}", uid), &updates)
114            .await
115    }
116
117    /// Configure modules for a specific database - POST /v1/modules/config/bdb/{uid}
118    pub async fn config_bdb(&self, bdb_uid: u32, config: Value) -> Result<Module> {
119        self.client
120            .post(&format!("/v1/modules/config/bdb/{}", bdb_uid), &config)
121            .await
122    }
123}