Struct td_rredis::Cmd

source ·
pub struct Cmd { /* private fields */ }
Expand description

Represents redis commands.

Implementations§

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:

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

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

td_rredis::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:

Creates a new empty command.

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:

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

Returns the packed command as a byte vector.

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.

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

Returns true if the command is in scan mode.

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

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 _ : () = td_rredis::cmd("PING").query(&con).unwrap();

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.