pub struct Client { /* private fields */ }Expand description
High-level Redis client
Automatically handles:
- Topology detection (Standalone vs Cluster)
- MOVED and ASK redirects in cluster mode
- Connection pooling (multiplexed or traditional)
- Reconnection with exponential backoff
Implementations§
Source§impl Client
impl Client
Sourcepub async fn connect(config: ConnectionConfig) -> RedisResult<Self>
pub async fn connect(config: ConnectionConfig) -> RedisResult<Self>
Connect to Redis with the given configuration
This will automatically detect whether you’re connecting to a standalone Redis server or a Redis Cluster.
§Example
use redis_oxide::{Client, ConnectionConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ConnectionConfig::new("redis://localhost:6379");
let client = Client::connect(config).await?;
Ok(())
}Sourcepub async fn get(&self, key: impl Into<String>) -> RedisResult<Option<String>>
pub async fn get(&self, key: impl Into<String>) -> RedisResult<Option<String>>
Get the value of a key
Sourcepub async fn set(
&self,
key: impl Into<String>,
value: impl Into<String>,
) -> RedisResult<bool>
pub async fn set( &self, key: impl Into<String>, value: impl Into<String>, ) -> RedisResult<bool>
Set the value of a key
Sourcepub async fn set_ex(
&self,
key: impl Into<String>,
value: impl Into<String>,
expiration: Duration,
) -> RedisResult<bool>
pub async fn set_ex( &self, key: impl Into<String>, value: impl Into<String>, expiration: Duration, ) -> RedisResult<bool>
Set the value of a key with expiration
Sourcepub async fn set_nx(
&self,
key: impl Into<String>,
value: impl Into<String>,
) -> RedisResult<bool>
pub async fn set_nx( &self, key: impl Into<String>, value: impl Into<String>, ) -> RedisResult<bool>
Set the value of a key only if it doesn’t exist
Sourcepub async fn exists(&self, keys: Vec<String>) -> RedisResult<i64>
pub async fn exists(&self, keys: Vec<String>) -> RedisResult<i64>
Check if one or more keys exist
Sourcepub async fn expire(
&self,
key: impl Into<String>,
duration: Duration,
) -> RedisResult<bool>
pub async fn expire( &self, key: impl Into<String>, duration: Duration, ) -> RedisResult<bool>
Set a key’s time to live in seconds
Sourcepub async fn ttl(&self, key: impl Into<String>) -> RedisResult<Option<i64>>
pub async fn ttl(&self, key: impl Into<String>) -> RedisResult<Option<i64>>
Get the time to live for a key
Sourcepub async fn incr(&self, key: impl Into<String>) -> RedisResult<i64>
pub async fn incr(&self, key: impl Into<String>) -> RedisResult<i64>
Increment the integer value of a key by one
Sourcepub async fn decr(&self, key: impl Into<String>) -> RedisResult<i64>
pub async fn decr(&self, key: impl Into<String>) -> RedisResult<i64>
Decrement the integer value of a key by one
Sourcepub async fn incr_by(
&self,
key: impl Into<String>,
increment: i64,
) -> RedisResult<i64>
pub async fn incr_by( &self, key: impl Into<String>, increment: i64, ) -> RedisResult<i64>
Increment the integer value of a key by the given amount
Sourcepub async fn decr_by(
&self,
key: impl Into<String>,
decrement: i64,
) -> RedisResult<i64>
pub async fn decr_by( &self, key: impl Into<String>, decrement: i64, ) -> RedisResult<i64>
Decrement the integer value of a key by the given amount
Sourcepub fn topology_type(&self) -> TopologyType
pub fn topology_type(&self) -> TopologyType
Get the topology type
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
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
Mutably borrows from an owned value. Read more