[][src]Struct redis::Pipeline

pub struct Pipeline { /* fields omitted */ }

Represents a redis command pipeline.

Methods

impl Pipeline[src]

A pipeline allows you to send multiple commands in one go to the redis server. API wise it's very similar to just using a command but it allows multiple commands to be chained and some features such as iteration are not available.

Basic example:

let ((k1, k2),) : ((i32, i32),) = redis::pipe()
    .cmd("SET").arg("key_1").arg(42).ignore()
    .cmd("SET").arg("key_2").arg(43).ignore()
    .cmd("MGET").arg(&["key_1", "key_2"]).query(&mut con).unwrap();

As you can see with cmd you can start a new command. By default each command produces a value but for some you can ignore them by calling ignore on the command. That way it will be skipped in the return value which is useful for SET commands and others, which do not have a useful return value.

pub fn new() -> Pipeline[src]

Creates an empty pipeline. For consistency with the cmd api a pipe function is provided as alias.

pub fn with_capacity(capacity: usize) -> Pipeline[src]

Creates an empty pipeline with pre-allocated capacity.

pub fn cmd(&mut self, name: &str) -> &mut Pipeline[src]

Starts a new command. Functions such as arg then become available to add more arguments to that command.

pub fn add_command(&mut self, cmd: Cmd) -> &mut Pipeline[src]

Adds a command to the pipeline.

pub fn arg<T: ToRedisArgs>(&mut self, arg: T) -> &mut Pipeline[src]

Adds an argument to the last started command. This works similar to the arg method of the Cmd object.

Note that this function fails the task if executed on an empty pipeline.

pub fn ignore(&mut self) -> &mut Pipeline[src]

Instructs the pipeline to ignore the return value of this command. It will still be ensured that it is not an error, but any successful result is just thrown away. This makes result processing through tuples much easier because you do not need to handle all the items you do not care about.

Note that this function fails the task if executed on an empty pipeline.

pub fn atomic(&mut self) -> &mut Pipeline[src]

This enables atomic mode. In atomic mode the whole pipeline is enclosed in MULTI/EXEC. From the user's point of view nothing changes however. This is easier than using MULTI/EXEC yourself as the format does not change.

let (k1, k2) : (i32, i32) = redis::pipe()
    .atomic()
    .cmd("GET").arg("key_1")
    .cmd("GET").arg("key_2").query(&mut con).unwrap();

pub fn get_packed_pipeline(&self, atomic: bool) -> Vec<u8>[src]

Returns the encoded pipeline commands.

pub fn query<T: FromRedisValue>(
    &self,
    con: &mut dyn ConnectionLike
) -> RedisResult<T>
[src]

Executes the pipeline and fetches the return values. Since most pipelines return different types it's recommended to use tuple matching to process the results:

let (k1, k2) : (i32, i32) = redis::pipe()
    .cmd("SET").arg("key_1").arg(42).ignore()
    .cmd("SET").arg("key_2").arg(43).ignore()
    .cmd("GET").arg("key_1")
    .cmd("GET").arg("key_2").query(&mut con).unwrap();

NOTE: A Pipeline object may be reused after query() with all the commands as were inserted to them. In order to clear a Pipeline object with minimal memory released/allocated, it is necessary to call the clear() before inserting new commands.

pub fn clear(&mut self)[src]

Clear a Pipeline object internal data structure.

This allows reusing a Pipeline object as a clear object while performing a minimal amount of memory released/reallocated.

pub fn query_async<C, T: FromRedisValue>(self, con: C) -> RedisFuture<(C, T)> where
    C: ConnectionLike + Send + 'static,
    T: Send + 'static, 
[src]

Async version of query.

pub fn execute(&self, con: &mut dyn ConnectionLike)[src]

This is a shortcut to query() that does not return a value and will fail the task if the query of the pipeline fails.

This is equivalent to a call of query like this:

let _ : () = redis::pipe().cmd("PING").query(&mut con).unwrap();

NOTE: A Pipeline object may be reused after query() with all the commands as were inserted to them. In order to clear a Pipeline object with minimal memory released/allocated, it is necessary to call the clear() before inserting new commands.

Trait Implementations

impl PipelineCommands for Pipeline[src]

impl Clone for Pipeline[src]

impl Default for Pipeline[src]

Auto Trait Implementations

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T