Pipeline

Struct Pipeline 

Source
pub struct Pipeline { /* private fields */ }
Expand description

A pipeline for batching Redis commands

Pipeline allows you to send multiple commands to Redis in a single network round-trip, which can significantly improve performance when executing many operations.

Implementations§

Source§

impl Pipeline

Source

pub fn new(connection: Arc<Mutex<dyn PipelineExecutor + Send + Sync>>) -> Self

Create a new pipeline

Source

pub fn add_command(&mut self, command: Box<dyn PipelineCommand>) -> &mut Self

Add a command to the pipeline

Source

pub fn set( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self

Add a SET command to the pipeline

Source

pub fn get(&mut self, key: impl Into<String>) -> &mut Self

Add a GET command to the pipeline

Source

pub fn del(&mut self, keys: Vec<String>) -> &mut Self

Add a DEL command to the pipeline

Source

pub fn incr(&mut self, key: impl Into<String>) -> &mut Self

Add an INCR command to the pipeline

Source

pub fn decr(&mut self, key: impl Into<String>) -> &mut Self

Add a DECR command to the pipeline

Source

pub fn incr_by(&mut self, key: impl Into<String>, increment: i64) -> &mut Self

Add an INCRBY command to the pipeline

Source

pub fn decr_by(&mut self, key: impl Into<String>, decrement: i64) -> &mut Self

Add a DECRBY command to the pipeline

Source

pub fn exists(&mut self, keys: Vec<String>) -> &mut Self

Add an EXISTS command to the pipeline

Source

pub fn expire(&mut self, key: impl Into<String>, seconds: Duration) -> &mut Self

Add an EXPIRE command to the pipeline

Source

pub fn ttl(&mut self, key: impl Into<String>) -> &mut Self

Add a TTL command to the pipeline

Source

pub fn hget( &mut self, key: impl Into<String>, field: impl Into<String>, ) -> &mut Self

Add an HGET command to the pipeline

Source

pub fn hset( &mut self, key: impl Into<String>, field: impl Into<String>, value: impl Into<String>, ) -> &mut Self

Add an HSET command to the pipeline

Source

pub fn hdel(&mut self, key: impl Into<String>, fields: Vec<String>) -> &mut Self

Add an HDEL command to the pipeline

Source

pub fn hgetall(&mut self, key: impl Into<String>) -> &mut Self

Add an HGETALL command to the pipeline

Source

pub fn hmget( &mut self, key: impl Into<String>, fields: Vec<String>, ) -> &mut Self

Add an HMGET command to the pipeline

Source

pub fn hmset( &mut self, key: impl Into<String>, fields: HashMap<String, String>, ) -> &mut Self

Add an HMSET command to the pipeline

Source

pub fn hlen(&mut self, key: impl Into<String>) -> &mut Self

Add an HLEN command to the pipeline

Source

pub fn lpush( &mut self, key: impl Into<String>, values: Vec<String>, ) -> &mut Self

Add an LPUSH command to the pipeline

Source

pub fn rpush( &mut self, key: impl Into<String>, values: Vec<String>, ) -> &mut Self

Add an RPUSH command to the pipeline

Source

pub fn lrange( &mut self, key: impl Into<String>, start: i64, stop: i64, ) -> &mut Self

Add an LRANGE command to the pipeline

Source

pub fn llen(&mut self, key: impl Into<String>) -> &mut Self

Add an LLEN command to the pipeline

Source

pub fn sadd( &mut self, key: impl Into<String>, members: Vec<String>, ) -> &mut Self

Add an SADD command to the pipeline

Source

pub fn smembers(&mut self, key: impl Into<String>) -> &mut Self

Add an SMEMBERS command to the pipeline

Source

pub fn hexists( &mut self, key: impl Into<String>, field: impl Into<String>, ) -> &mut Self

Add an HEXISTS command to the pipeline

Source

pub fn len(&self) -> usize

Get the number of commands in the pipeline

Source

pub fn is_empty(&self) -> bool

Check if the pipeline is empty

Source

pub fn clear(&mut self)

Clear all commands from the pipeline

Source

pub async fn execute(&mut self) -> RedisResult<Vec<RespValue>>

Execute all commands in the pipeline

This sends all batched commands to Redis in a single network round-trip and returns their results in the same order they were added.

§Errors

Returns an error if:

  • The pipeline is empty
  • Network communication fails
  • Any command in the pipeline fails
§Examples
let mut pipeline = client.pipeline();
pipeline.set("key1", "value1");
pipeline.get("key1");

let results = pipeline.execute().await?;
assert_eq!(results.len(), 2);
Source

pub async fn execute_typed<T>(&mut self) -> RedisResult<Vec<T>>

Execute the pipeline and return typed results

This is a convenience method that executes the pipeline and attempts to convert the results to the expected types.

§Errors

Returns an error if execution fails or type conversion fails.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more