zero4rs 2.0.0

zero4rs is a powerful, pragmatic, and extremely fast web framework for Rust
Documentation
use std::pin::Pin;

use redis::aio::AsyncStream;

#[allow(deprecated)]
use redis::aio::Connection;

use crate::core::{errors::Errors, redis::ReidsPubsubStandaloneAsync};

#[derive(Clone)]
pub struct ReidsPubSubAsync {
    pub standalone_client: Option<ReidsPubsubStandaloneAsync>,
}

impl ReidsPubSubAsync {
    #[allow(deprecated)]
    pub async fn get_connection(
        &self,
    ) -> Result<Connection<Pin<Box<dyn AsyncStream + Send + Sync>>>, Errors> {
        if let Some(l) = &self.standalone_client {
            return l.get_connection().await;
        }

        Err(Errors::GenericError("not support mode".to_string()))
    }

    pub async fn subscribe(
        &self,
        topic: &str,
    ) -> Result<futures::channel::mpsc::UnboundedReceiver<String>, Errors> {
        if let Some(l) = &self.standalone_client {
            return l.subscribe(topic).await;
        }

        Err(Errors::GenericError("not support mode".to_string()))
    }

    pub async fn subscribe2(&self, channel: &str) -> Result<(), Errors> {
        if let Some(l) = &self.standalone_client {
            return l.subscribe2(channel).await;
        }

        Err(Errors::GenericError("not support mode".to_string()))
    }

    pub fn subscribe3(&self, channel: &str, f: &dyn Fn(String, String)) {
        if let Some(l) = &self.standalone_client {
            l.subscribe3(channel, f);
        }
        panic!("not support mode");
    }
}