///Create a connection pool, but name each connection by `name`. Useful if you are running multiple services on a single Redis instance.
///# Panics
///Will panic if the number of connections is equal to zero.
Create a connection pool, but name each connection by `name`. Useful if you are running multiple services on a single Redis instance.
Create a connection pool but name each connection by ` name ` . Useful if you are running multiple services on a single Redis instance .
pub async fn create_with_name(
        name: &str,
        address: String,
        password: Option<&str>,
        connection_count: usize,
    ) -> Result<Self> {
        assert!(connection_count > 0);
        let connections = Vec::new();
        let mut out = Self {
            connections,
            name: Arc::new(name.to_string()),
            password: password.map(|s| Arc::new(s.to_string())),
            address: Arc::new(address),
        };
        for i in 0..connection_count {
            let mut conn = if let Some(p) = password {
                Connection::connect_and_auth(out.address.as_ref(), p).await?
            } else {
                Connection::connect(out.address.as_ref()).await?
            };
            let client_name = format!("{}-{}", name, i + 1);
            conn.run_command(Command::new("CLIENT").arg(b"SETNAME").arg(&client_name))
                .await?;
            out.connections.push(Arc::new(Mutex::new(conn)));
        }
        Ok(out)
    }
pub async fn create_with_name ( name : & str , address : String , password : Option < & str > , connection_count : usize , ) -> Result < Self > { assert ! ( connection_count 0 ) ; let connections = Vec :: new ( ) ; let mut out = Self { connections , name : Arc :: new ( name . to_string ( ) ) , password : password . map ( | s | Arc :: new ( s . to_string ( ) ) ) , address : Arc :: new ( address ) , } ; for i in 0 .. connection_count { let mut conn = if let Some ( p ) = password { Connection :: connect_and_auth ( out . address . as_ref ( ) , p ) . await ? } else { Connection :: connect ( out . address . as_ref ( ) ) . await ? } ; let client_name = format ! ( " " name i 1 ) ; conn . run_command ( Command :: new ( " " ) . arg ( b" " ) . arg ( & client_name ) ) . await ? ; out . connections . push ( Arc :: new ( Mutex :: new ( conn ) ) ) ; } Ok ( out ) }
Create a connection pool, but name each connection by `name`.
Create a connection pool but name each connection by ` name ` .
name
&str
address
String
password
Option<&str>
connection_count
usize
panics
Will panic if the number of connections is equal to zero.
Will panic if the number of connections is equal to zero .