redis_enterprise/
shards.rs

1//! Shard management for Redis Enterprise
2
3use crate::client::RestClient;
4use crate::error::Result;
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8/// Shard information
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct Shard {
11    pub uid: String,
12    pub bdb_uid: u32,
13    pub node_uid: u32,
14    pub role: String,
15    pub status: String,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub slots: Option<String>,
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub used_memory: Option<u64>,
20    #[serde(skip_serializing_if = "Option::is_none")]
21    pub backup_progress: Option<f64>,
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub import_progress: Option<f64>,
24
25    #[serde(flatten)]
26    pub extra: Value,
27}
28
29/// Shard stats information
30#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct ShardStats {
32    pub uid: String,
33    pub intervals: Vec<StatsInterval>,
34
35    #[serde(flatten)]
36    pub extra: Value,
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct StatsInterval {
41    pub interval: String,
42    pub timestamps: Vec<i64>,
43    pub values: Vec<Value>,
44}
45
46/// Shard handler for managing shards
47pub struct ShardHandler {
48    client: RestClient,
49}
50
51impl ShardHandler {
52    pub fn new(client: RestClient) -> Self {
53        ShardHandler { client }
54    }
55
56    /// List all shards
57    pub async fn list(&self) -> Result<Vec<Shard>> {
58        self.client.get("/v1/shards").await
59    }
60
61    /// Get specific shard information
62    pub async fn get(&self, uid: &str) -> Result<Shard> {
63        self.client.get(&format!("/v1/shards/{}", uid)).await
64    }
65
66    /// Get shard statistics
67    pub async fn stats(&self, uid: &str) -> Result<ShardStats> {
68        self.client.get(&format!("/v1/shards/{}/stats", uid)).await
69    }
70
71    /// Get shard statistics for a specific metric
72    pub async fn stats_metric(&self, uid: &str, metric: &str) -> Result<Value> {
73        self.client
74            .get(&format!("/v1/shards/{}/stats/{}", uid, metric))
75            .await
76    }
77
78    /// Get shards for a specific database
79    pub async fn list_by_database(&self, bdb_uid: u32) -> Result<Vec<Shard>> {
80        self.client
81            .get(&format!("/v1/bdbs/{}/shards", bdb_uid))
82            .await
83    }
84
85    /// Get shards for a specific node
86    pub async fn list_by_node(&self, node_uid: u32) -> Result<Vec<Shard>> {
87        self.client
88            .get(&format!("/v1/nodes/{}/shards", node_uid))
89            .await
90    }
91}