Struct ClusterCmd

Source
pub struct ClusterCmd { /* private fields */ }
Expand description

Redis::Cmd’s args field is private, but we need it to determine a slot from the command. So this is a simple wrapper around Redis::Cmd that keeps track of the args.

Implementations§

Source§

impl ClusterCmd

Source

pub fn new() -> ClusterCmd

Examples found in repository?
examples/basic.rs (line 11)
7fn main() {
8    let startup_nodes =
9        vec!["redis://127.0.0.1:7000", "redis://127.0.0.1:7001", "redis://127.0.0.1:7002"];
10    let mut clus = Cluster::new(startup_nodes);
11    let mut cmd = ClusterCmd::new();
12    cmd.arg("SET").arg("foo").arg("bar");
13    let _: () = clus.send_command(&cmd).unwrap();
14
15    let mut cmd = ClusterCmd::new();
16    cmd.arg("GET").arg("foo");
17    let res: String = clus.send_command(&cmd).unwrap();
18    println!("{:?}", res);
19    assert_eq!(res, "bar");
20
21    let _: () = clus.set("hey", "there").unwrap();
22    let res: String = clus.get("hey").unwrap();
23    println!("{:?}", res);
24    assert_eq!(res, "there");
25}
Source

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

Add an arg to the command.

Examples found in repository?
examples/basic.rs (line 12)
7fn main() {
8    let startup_nodes =
9        vec!["redis://127.0.0.1:7000", "redis://127.0.0.1:7001", "redis://127.0.0.1:7002"];
10    let mut clus = Cluster::new(startup_nodes);
11    let mut cmd = ClusterCmd::new();
12    cmd.arg("SET").arg("foo").arg("bar");
13    let _: () = clus.send_command(&cmd).unwrap();
14
15    let mut cmd = ClusterCmd::new();
16    cmd.arg("GET").arg("foo");
17    let res: String = clus.send_command(&cmd).unwrap();
18    println!("{:?}", res);
19    assert_eq!(res, "bar");
20
21    let _: () = clus.set("hey", "there").unwrap();
22    let res: String = clus.get("hey").unwrap();
23    println!("{:?}", res);
24    assert_eq!(res, "there");
25}
Source

pub fn query<T: FromRedisValue>(&self, conn: &Connection) -> RedisResult<T>

Execute the command, returning the result.

Source

pub fn slot(&self) -> Option<u16>

Get the slot for this command.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.