Struct RedisPool

Source
pub struct RedisPool { /* private fields */ }

Implementations§

Source§

impl RedisPool

Source

pub fn max_connections(&mut self, size: u32) -> &mut Self

Examples found in repository?
examples/basic.rs (line 11)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut pool: RedisPool = RedisPool::from_str("localhost:6379").unwrap();
8    // Or from SocketAddr
9    // let mut pool = RedisPool::from(SocketAddr::from(([127, 0, 0, 1], 6379)));
10
11    let _ = pool.max_connections(10).establish_pool().await?;
12
13    pool.send_command("SET foo bar").await?;
14
15    Ok(())
16}
More examples
Hide additional examples
examples/read_from_stream.rs (line 14)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let mut pool = RedisPool::from_str("localhost:6379").unwrap();
11    // Or from SocketAddr
12    // let mut pool = RedisPool::from(SocketAddr::from(([127, 0, 0, 1], 6379)));
13
14    let _ = pool.max_connections(10).establish_pool().await?;
15
16    let redis_connection: Rc<RefCell<RedisConnection>> = pool.send_command("SET foo bar").await?;
17
18    let mut redis_connection_guard = redis_connection.borrow_mut();
19
20    let mut buffer = [0; 1024];
21
22    redis_connection_guard.stream.read(&mut buffer).await?;
23
24    println!("Response: {}", String::from_utf8_lossy(&buffer)); // Response: +OK
25
26    let redis_connection: Rc<RefCell<RedisConnection>> = pool.send_command("PING").await?;
27
28    let mut redis_connection_guard = redis_connection.borrow_mut();
29
30    let mut buffer = [0; 1024];
31
32    redis_connection_guard.stream.read(&mut buffer).await?;
33
34    println!("Response: {}", String::from_utf8_lossy(&buffer)); // Response: +PONG
35
36    Ok(())
37}
Source

pub async fn establish_pool(&mut self) -> Result<(), RedisError>

Examples found in repository?
examples/basic.rs (line 11)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut pool: RedisPool = RedisPool::from_str("localhost:6379").unwrap();
8    // Or from SocketAddr
9    // let mut pool = RedisPool::from(SocketAddr::from(([127, 0, 0, 1], 6379)));
10
11    let _ = pool.max_connections(10).establish_pool().await?;
12
13    pool.send_command("SET foo bar").await?;
14
15    Ok(())
16}
More examples
Hide additional examples
examples/read_from_stream.rs (line 14)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let mut pool = RedisPool::from_str("localhost:6379").unwrap();
11    // Or from SocketAddr
12    // let mut pool = RedisPool::from(SocketAddr::from(([127, 0, 0, 1], 6379)));
13
14    let _ = pool.max_connections(10).establish_pool().await?;
15
16    let redis_connection: Rc<RefCell<RedisConnection>> = pool.send_command("SET foo bar").await?;
17
18    let mut redis_connection_guard = redis_connection.borrow_mut();
19
20    let mut buffer = [0; 1024];
21
22    redis_connection_guard.stream.read(&mut buffer).await?;
23
24    println!("Response: {}", String::from_utf8_lossy(&buffer)); // Response: +OK
25
26    let redis_connection: Rc<RefCell<RedisConnection>> = pool.send_command("PING").await?;
27
28    let mut redis_connection_guard = redis_connection.borrow_mut();
29
30    let mut buffer = [0; 1024];
31
32    redis_connection_guard.stream.read(&mut buffer).await?;
33
34    println!("Response: {}", String::from_utf8_lossy(&buffer)); // Response: +PONG
35
36    Ok(())
37}
Source

pub async fn send_command( &mut self, command: &str, ) -> Result<Rc<RefCell<RedisConnection>>, RedisError>

Examples found in repository?
examples/basic.rs (line 13)
6async fn main() -> Result<(), Box<dyn std::error::Error>> {
7    let mut pool: RedisPool = RedisPool::from_str("localhost:6379").unwrap();
8    // Or from SocketAddr
9    // let mut pool = RedisPool::from(SocketAddr::from(([127, 0, 0, 1], 6379)));
10
11    let _ = pool.max_connections(10).establish_pool().await?;
12
13    pool.send_command("SET foo bar").await?;
14
15    Ok(())
16}
More examples
Hide additional examples
examples/read_from_stream.rs (line 16)
9async fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let mut pool = RedisPool::from_str("localhost:6379").unwrap();
11    // Or from SocketAddr
12    // let mut pool = RedisPool::from(SocketAddr::from(([127, 0, 0, 1], 6379)));
13
14    let _ = pool.max_connections(10).establish_pool().await?;
15
16    let redis_connection: Rc<RefCell<RedisConnection>> = pool.send_command("SET foo bar").await?;
17
18    let mut redis_connection_guard = redis_connection.borrow_mut();
19
20    let mut buffer = [0; 1024];
21
22    redis_connection_guard.stream.read(&mut buffer).await?;
23
24    println!("Response: {}", String::from_utf8_lossy(&buffer)); // Response: +OK
25
26    let redis_connection: Rc<RefCell<RedisConnection>> = pool.send_command("PING").await?;
27
28    let mut redis_connection_guard = redis_connection.borrow_mut();
29
30    let mut buffer = [0; 1024];
31
32    redis_connection_guard.stream.read(&mut buffer).await?;
33
34    println!("Response: {}", String::from_utf8_lossy(&buffer)); // Response: +PONG
35
36    Ok(())
37}

Trait Implementations§

Source§

impl From<SocketAddr> for RedisPool

Source§

fn from(addr: SocketAddr) -> Self

Converts to this type from the input type.
Source§

impl FromStr for RedisPool

Source§

type Err = RedisError

The associated error which can be returned from parsing.
Source§

fn from_str(connection_str: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.