redis-enterprise 0.9.1

Redis Enterprise REST API client library
Documentation
//! Database group configuration
//!
//! ## Overview
//! - Manage database groups
//! - Configure group settings
//! - Query group membership

use crate::client::RestClient;
use crate::error::Result;
use serde::{Deserialize, Serialize};

/// Database group information
/// Represents a group of databases that share a memory pool
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BdbGroup {
    /// Cluster unique ID of the database group
    pub uid: u32,
    /// Group name (may be auto-generated if not specified)
    pub name: String,
    /// The common memory pool size limit for all databases in the group, expressed in bytes
    #[serde(skip_serializing_if = "Option::is_none")]
    pub memory_size: Option<u64>,
    /// A list of UIDs of member databases (read-only)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub members: Option<Vec<String>>,
}

/// Response wrapper for `GET /v1/bdb_groups`.
///
/// The API returns `{"bdb_groups": [...]}`. Kept private; consumers go
/// through [`BdbGroupsHandler::list`] which unwraps to a flat
/// `Vec<BdbGroup>`.
#[derive(Debug, Clone, Deserialize)]
struct BdbGroupsListResponse {
    #[serde(default)]
    bdb_groups: Vec<BdbGroup>,
}

/// Handler for database group operations
pub struct BdbGroupsHandler {
    client: RestClient,
}

impl BdbGroupsHandler {
    /// Create a new handler bound to the given REST client.
    pub fn new(client: RestClient) -> Self {
        BdbGroupsHandler { client }
    }

    /// List all database groups.
    ///
    /// `GET /v1/bdb_groups`. The API wraps the array under a
    /// `bdb_groups` key; this method unwraps the wrapper so callers
    /// get a flat `Vec<BdbGroup>`.
    pub async fn list(&self) -> Result<Vec<BdbGroup>> {
        let resp: BdbGroupsListResponse = self.client.get("/v1/bdb_groups").await?;
        Ok(resp.bdb_groups)
    }

    /// Get a single database group by UID.
    pub async fn get(&self, uid: u32) -> Result<BdbGroup> {
        self.client.get(&format!("/v1/bdb_groups/{}", uid)).await
    }

    /// Create a new database group.
    pub async fn create(&self, body: CreateBdbGroupRequest) -> Result<BdbGroup> {
        self.client.post("/v1/bdb_groups", &body).await
    }

    /// Update an existing database group.
    pub async fn update(&self, uid: u32, body: UpdateBdbGroupRequest) -> Result<BdbGroup> {
        self.client
            .put(&format!("/v1/bdb_groups/{}", uid), &body)
            .await
    }

    /// Delete a database group.
    pub async fn delete(&self, uid: u32) -> Result<()> {
        self.client.delete(&format!("/v1/bdb_groups/{}", uid)).await
    }
}

/// Request to create a new database group
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreateBdbGroupRequest {
    /// Name.
    pub name: String,
}

/// Request to update an existing database group
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdateBdbGroupRequest {
    /// Name.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
}