redis_enterprise/
modules.rs1use crate::client::RestClient;
4use crate::error::Result;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8#[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#[derive(Debug, Serialize)]
30pub struct UploadModuleRequest {
31 pub module: Vec<u8>, }
33
34pub struct ModuleHandler {
36 client: RestClient,
37}
38
39impl ModuleHandler {
40 pub fn new(client: RestClient) -> Self {
41 ModuleHandler { client }
42 }
43
44 pub async fn list(&self) -> Result<Vec<Module>> {
46 self.client.get("/v1/modules").await
47 }
48
49 pub async fn get(&self, uid: &str) -> Result<Module> {
51 self.client.get(&format!("/v1/modules/{}", uid)).await
52 }
53
54 pub async fn upload(&self, module_data: Vec<u8>) -> Result<Module> {
56 let request = UploadModuleRequest {
59 module: module_data,
60 };
61 self.client.post("/v1/modules", &request).await
62 }
63
64 pub async fn delete(&self, uid: &str) -> Result<()> {
66 self.client.delete(&format!("/v1/modules/{}", uid)).await
67 }
68
69 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}