[][src]Struct redis::Cmd

pub struct Cmd { /* fields omitted */ }

Represents redis commands.

Methods

impl Cmd[src]

A command acts as a builder interface to creating encoded redis requests. This allows you to easiy assemble a packed command by chaining arguments together.

Basic example:

redis::Cmd::new().arg("SET").arg("my_key").arg(42);

There is also a helper function called cmd which makes it a tiny bit shorter:

redis::cmd("SET").arg("my_key").arg(42);

Because currently rust's currently does not have an ideal system for lifetimes of temporaries, sometimes you need to hold on to the initially generated command:

let mut cmd = redis::cmd("SMEMBERS");
let mut iter : redis::Iter<i32> = cmd.arg("my_set").iter(&con).unwrap();

pub fn new() -> Cmd[src]

Creates a new empty command.

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

Appends an argument to the command. The argument passed must be a type that implements ToRedisArgs. Most primitive types as well as vectors of primitive types implement it.

For instance all of the following are valid:

redis::cmd("SET").arg(&["my_key", "my_value"]);
redis::cmd("SET").arg("my_key").arg(42);
redis::cmd("SET").arg("my_key").arg(b"my_value");

pub fn cursor_arg(&mut self, cursor: u64) -> &mut Cmd[src]

Works similar to arg but adds a cursor argument. This is always an integer and also flips the command implementation to support a different mode for the iterators where the iterator will ask for another batch of items when the local data is exhausted.

let mut cmd = redis::cmd("SSCAN");
let mut iter : redis::Iter<isize> = cmd.arg("my_set").cursor_arg(0).iter(&con).unwrap();
for x in iter {
    // do something with the item
}

pub fn get_packed_command(&self) -> Vec<u8>[src]

Returns the packed command as a byte vector.

pub fn in_scan_mode(&self) -> bool[src]

Returns true if the command is in scan mode.

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

Sends the command as query to the connection and converts the result to the target redis value. This is the general way how you can retrieve data.

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

pub fn iter<'a, T: FromRedisValue>(
    &self,
    con: &'a dyn ConnectionLike
) -> RedisResult<Iter<'a, T>>
[src]

Similar to query() but returns an iterator over the items of the bulk result or iterator. In normal mode this is not in any way more efficient than just querying into a Vec<T> as it's internally implemented as buffering into a vector. This however is useful when cursor_arg was used in which case the iterator will query for more items until the server side cursor is exhausted.

This is useful for commands such as SSCAN, SCAN and others.

One speciality of this function is that it will check if the response looks like a cursor or not and always just looks at the payload. This way you can use the function the same for responses in the format of KEYS (just a list) as well as SSCAN (which returns a tuple of cursor and list).

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

This is a shortcut to query() that does not return a value and will fail the task if the query fails because of an error. This is mainly useful in examples and for simple commands like setting keys.

This is equivalent to a call of query like this:

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

Trait Implementations

impl Clone for Cmd[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Cmd

impl Sync for Cmd

Blanket Implementations

impl<T> From for T[src]

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

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

type Owned = T

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Erased for T