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
impl Pipeline
Sourcepub fn new(connection: Arc<Mutex<dyn PipelineExecutor + Send + Sync>>) -> Self
pub fn new(connection: Arc<Mutex<dyn PipelineExecutor + Send + Sync>>) -> Self
Create a new pipeline
Sourcepub fn add_command(&mut self, command: Box<dyn PipelineCommand>) -> &mut Self
pub fn add_command(&mut self, command: Box<dyn PipelineCommand>) -> &mut Self
Add a command to the pipeline
Sourcepub fn set(
&mut self,
key: impl Into<String>,
value: impl Into<String>,
) -> &mut Self
pub fn set( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self
Add a SET command to the pipeline
Sourcepub fn incr(&mut self, key: impl Into<String>) -> &mut Self
pub fn incr(&mut self, key: impl Into<String>) -> &mut Self
Add an INCR command to the pipeline
Sourcepub fn incr_by(&mut self, key: impl Into<String>, increment: i64) -> &mut Self
pub fn incr_by(&mut self, key: impl Into<String>, increment: i64) -> &mut Self
Add an INCRBY command to the pipeline
Sourcepub fn decr_by(&mut self, key: impl Into<String>, decrement: i64) -> &mut Self
pub fn decr_by(&mut self, key: impl Into<String>, decrement: i64) -> &mut Self
Add a DECRBY command to the pipeline
Sourcepub fn expire(&mut self, key: impl Into<String>, seconds: Duration) -> &mut Self
pub fn expire(&mut self, key: impl Into<String>, seconds: Duration) -> &mut Self
Add an EXPIRE command to the pipeline
Sourcepub fn hget(
&mut self,
key: impl Into<String>,
field: impl Into<String>,
) -> &mut Self
pub fn hget( &mut self, key: impl Into<String>, field: impl Into<String>, ) -> &mut Self
Add an HGET command to the pipeline
Sourcepub fn hset(
&mut self,
key: impl Into<String>,
field: impl Into<String>,
value: impl Into<String>,
) -> &mut Self
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
Sourcepub fn hdel(&mut self, key: impl Into<String>, fields: Vec<String>) -> &mut Self
pub fn hdel(&mut self, key: impl Into<String>, fields: Vec<String>) -> &mut Self
Add an HDEL command to the pipeline
Sourcepub fn hgetall(&mut self, key: impl Into<String>) -> &mut Self
pub fn hgetall(&mut self, key: impl Into<String>) -> &mut Self
Add an HGETALL command to the pipeline
Sourcepub fn hmget(
&mut self,
key: impl Into<String>,
fields: Vec<String>,
) -> &mut Self
pub fn hmget( &mut self, key: impl Into<String>, fields: Vec<String>, ) -> &mut Self
Add an HMGET command to the pipeline
Sourcepub fn hmset(
&mut self,
key: impl Into<String>,
fields: HashMap<String, String>,
) -> &mut Self
pub fn hmset( &mut self, key: impl Into<String>, fields: HashMap<String, String>, ) -> &mut Self
Add an HMSET command to the pipeline
Sourcepub fn hlen(&mut self, key: impl Into<String>) -> &mut Self
pub fn hlen(&mut self, key: impl Into<String>) -> &mut Self
Add an HLEN command to the pipeline
Sourcepub fn lpush(
&mut self,
key: impl Into<String>,
values: Vec<String>,
) -> &mut Self
pub fn lpush( &mut self, key: impl Into<String>, values: Vec<String>, ) -> &mut Self
Add an LPUSH command to the pipeline
Sourcepub fn rpush(
&mut self,
key: impl Into<String>,
values: Vec<String>,
) -> &mut Self
pub fn rpush( &mut self, key: impl Into<String>, values: Vec<String>, ) -> &mut Self
Add an RPUSH command to the pipeline
Sourcepub fn lrange(
&mut self,
key: impl Into<String>,
start: i64,
stop: i64,
) -> &mut Self
pub fn lrange( &mut self, key: impl Into<String>, start: i64, stop: i64, ) -> &mut Self
Add an LRANGE command to the pipeline
Sourcepub fn llen(&mut self, key: impl Into<String>) -> &mut Self
pub fn llen(&mut self, key: impl Into<String>) -> &mut Self
Add an LLEN command to the pipeline
Sourcepub fn sadd(
&mut self,
key: impl Into<String>,
members: Vec<String>,
) -> &mut Self
pub fn sadd( &mut self, key: impl Into<String>, members: Vec<String>, ) -> &mut Self
Add an SADD command to the pipeline
Sourcepub fn smembers(&mut self, key: impl Into<String>) -> &mut Self
pub fn smembers(&mut self, key: impl Into<String>) -> &mut Self
Add an SMEMBERS command to the pipeline
Sourcepub fn hexists(
&mut self,
key: impl Into<String>,
field: impl Into<String>,
) -> &mut Self
pub fn hexists( &mut self, key: impl Into<String>, field: impl Into<String>, ) -> &mut Self
Add an HEXISTS command to the pipeline
Sourcepub async fn execute(&mut self) -> RedisResult<Vec<RespValue>>
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);Sourcepub async fn execute_typed<T>(&mut self) -> RedisResult<Vec<T>>
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.