redis_enterprise/
shards.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 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#[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
46pub struct ShardHandler {
48 client: RestClient,
49}
50
51impl ShardHandler {
52 pub fn new(client: RestClient) -> Self {
53 ShardHandler { client }
54 }
55
56 pub async fn list(&self) -> Result<Vec<Shard>> {
58 self.client.get("/v1/shards").await
59 }
60
61 pub async fn get(&self, uid: &str) -> Result<Shard> {
63 self.client.get(&format!("/v1/shards/{}", uid)).await
64 }
65
66 pub async fn stats(&self, uid: &str) -> Result<ShardStats> {
68 self.client.get(&format!("/v1/shards/{}/stats", uid)).await
69 }
70
71 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 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 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}