redis_enterprise/
modules.rs

1//! Redis module management for Redis Enterprise
2
3use crate::client::RestClient;
4use crate::error::Result;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// Module information
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Module {
11    pub uid: String,
12    pub name: String,
13    pub version: String,
14    pub semantic_version: Option<String>,
15    pub author: Option<String>,
16    pub description: Option<String>,
17    pub homepage: Option<String>,
18    pub license: Option<String>,
19    pub command_line_args: Option<String>,
20    pub capabilities: Option<Vec<String>>,
21    pub min_redis_version: Option<String>,
22    pub min_redis_pack_version: Option<String>,
23
24    #[serde(flatten)]
25    pub extra: Value,
26}
27
28/// Module upload request
29#[derive(Debug, Serialize)]
30pub struct UploadModuleRequest {
31    pub module: Vec<u8>, // Binary module data
32}
33
34/// Module handler for managing Redis modules
35pub struct ModuleHandler {
36    client: RestClient,
37}
38
39impl ModuleHandler {
40    pub fn new(client: RestClient) -> Self {
41        ModuleHandler { client }
42    }
43
44    /// List all modules
45    pub async fn list(&self) -> Result<Vec<Module>> {
46        self.client.get("/v1/modules").await
47    }
48
49    /// Get specific module
50    pub async fn get(&self, uid: &str) -> Result<Module> {
51        self.client.get(&format!("/v1/modules/{}", uid)).await
52    }
53
54    /// Upload new module
55    pub async fn upload(&self, module_data: Vec<u8>) -> Result<Module> {
56        // Note: This endpoint typically requires multipart/form-data
57        // The actual implementation would need to handle file upload
58        let request = UploadModuleRequest {
59            module: module_data,
60        };
61        self.client.post("/v1/modules", &request).await
62    }
63
64    /// Delete module
65    pub async fn delete(&self, uid: &str) -> Result<()> {
66        self.client.delete(&format!("/v1/modules/{}", uid)).await
67    }
68
69    /// Update module configuration
70    pub async fn update(&self, uid: &str, updates: Value) -> Result<Module> {
71        self.client
72            .put(&format!("/v1/modules/{}", uid), &updates)
73            .await
74    }
75}