pub struct RedisConnection { /* private fields */ }Expand description
Redis connection wrapper that manages connection lifecycle.
Supports both single-node and cluster connections based on configuration.
Implementations§
Source§impl RedisConnection
impl RedisConnection
Sourcepub fn new(url: &str) -> Result<Self>
pub fn new(url: &str) -> Result<Self>
Create a new Redis connection from a URL.
§Arguments
url- Redis connection URL (e.g., “redis://localhost:6379”)
For cluster connections, use redis+cluster:// scheme or [from_config].
§Examples
// Single node
let conn = RedisConnection::new("redis://localhost:6379")?;
// Cluster (auto-detected from scheme)
let conn = RedisConnection::new("redis+cluster://node1:7000")?;Sourcepub fn from_config(config: ConnectionConfig) -> Result<Self>
pub fn from_config(config: ConnectionConfig) -> Result<Self>
Create a connection from a configuration.
§Examples
// Single node
let config = ConnectionConfig::single("redis://localhost:6379");
let conn = RedisConnection::from_config(config)?;
// Cluster with multiple initial nodes
let config = ConnectionConfig::cluster(&[
"redis://node1:7000",
"redis://node2:7001",
]);
let conn = RedisConnection::from_config(config)?;Sourcepub fn is_cluster(&self) -> bool
pub fn is_cluster(&self) -> bool
Check if this is a cluster connection.
Sourcepub async fn get_connection(&self) -> Result<RedisConn>
pub async fn get_connection(&self) -> Result<RedisConn>
Get a unified async connection.
Returns a RedisConn that works with both single-node and cluster.
Sourcepub async fn get_async_connection(&self) -> Result<MultiplexedConnection>
pub async fn get_async_connection(&self) -> Result<MultiplexedConnection>
Get an async multiplexed connection (single-node only).
Sourcepub async fn get_connection_manager(&self) -> Result<ConnectionManager>
pub async fn get_connection_manager(&self) -> Result<ConnectionManager>
Get a ConnectionManager for async operations with auto-reconnection.
ConnectionManager is cheap to clone and provides automatic reconnection
on connection failures. Preferred over get_async_connection() for
long-running operations.
Sourcepub fn get_sync_connection(&self) -> Result<Connection>
pub fn get_sync_connection(&self) -> Result<Connection>
Get a sync connection (for simple operations, single-node only).
Auto Trait Implementations§
impl Freeze for RedisConnection
impl RefUnwindSafe for RedisConnection
impl Send for RedisConnection
impl Sync for RedisConnection
impl Unpin for RedisConnection
impl UnwindSafe for RedisConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more