[−][src]Struct redis::Cmd
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").clone().iter(&mut 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).clone().iter(&mut 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: &mut dyn ConnectionLike
) -> RedisResult<T>
[src]
&self,
con: &mut dyn 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.
pub fn query_async<C, T: FromRedisValue>(&self, con: C) -> RedisFuture<(C, T)> where
C: ConnectionLike + Send + 'static,
T: Send + 'static,
[src]
C: ConnectionLike + Send + 'static,
T: Send + 'static,
pub fn iter<'a, T: FromRedisValue>(
self,
con: &'a mut dyn ConnectionLike
) -> RedisResult<Iter<'a, T>>
[src]
self,
con: &'a mut dyn 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).
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 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(&mut con).unwrap();
Trait Implementations
Auto Trait Implementations
impl Unpin for Cmd
impl Sync for Cmd
impl Send for Cmd
impl UnwindSafe for Cmd
impl RefUnwindSafe for Cmd
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,