Struct redis::Cmd [] [src]

pub struct Cmd {
    // some 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();

fn new() -> Cmd

Creates a new empty command.

fn arg<T: ToRedisArgs>(&mut self, arg: T) -> &mut Cmd

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");

fn cursor_arg(&mut self, cursor: u64) -> &mut Cmd

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
}

fn get_packed_command(&self) -> Vec<u8>

Returns the packed command as a byte vector.

fn in_scan_mode(&self) -> bool

Returns true if the command is in scan mode.

fn query<T: FromRedisValue>(&self, con: &ConnectionLike) -> RedisResult<T>

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.

fn iter<'a, T: FromRedisValue>(&self, con: &'a ConnectionLike) -> RedisResult<Iter<'a, T>>

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).

fn execute(&self, con: &ConnectionLike)

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(&self) -> Cmd

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more