Ctx

Struct Ctx 

Source
pub struct Ctx {
    pub ip: IpAddr,
    pub pipe: Pipeline<Client>,
    pub user_id: u64,
    pub site_id: u64,
    pub lang_id: u8,
    pub device_id: u64,
    pub bin: Vec<u8>,
    pub ipbin: Vec<u8>,
    pub site_key: Vec<u8>,
}

Fields§

§ip: IpAddr§pipe: Pipeline<Client>§user_id: u64§site_id: u64§lang_id: u8§device_id: u64§bin: Vec<u8>§ipbin: Vec<u8>§site_key: Vec<u8>

Implementations§

Source§

impl Ctx

Source

pub fn new( ip: IpAddr, user_id: u64, site_id: u64, lang_id: u8, device_id: u64, ) -> Self

Methods from Deref<Target = Pipeline<Client>>§

Source

pub async fn all<R>(&self) -> Result<R, Error>
where R: FromValue,

Send the pipeline and respond with an array of all responses.

async fn example(client: &Client) -> Result<(), Error> {
  let _ = client.mset(vec![("foo", 1), ("bar", 2)]).await?;

  let pipeline = client.pipeline();
  let _: () = pipeline.get("foo").await?; // returns when the command is queued in memory
  let _: () = pipeline.get("bar").await?; // returns when the command is queued in memory

  let results: Vec<i64> = pipeline.all().await?;
  assert_eq!(results, vec![1, 2]);
  Ok(())
}
Source

pub async fn try_all<R>(&self) -> Vec<Result<R, Error>>
where R: FromValue,

Send the pipeline and respond with each individual result.

Note: use Value as the return type (and convert as needed) to support an array of different return types.

async fn example(client: &Client) -> Result<(), Error> {
  let _ = client.mset(vec![("foo", 1), ("bar", 2)]).await?;  

  let pipeline = client.pipeline();
  let _: () = pipeline.get("foo").await?;
  let _: () = pipeline.hgetall("bar").await?; // this will error since `bar` is an integer

  let results = pipeline.try_all::<Value>().await;
  assert_eq!(results[0].clone()?.convert::<i64>()?, 1);
  assert!(results[1].is_err());

  Ok(())
}
Source

pub async fn last<R>(&self) -> Result<R, Error>
where R: FromValue,

Send the pipeline and respond with only the result of the last command.

async fn example(client: &Client) -> Result<(), Error> {
  let pipeline = client.pipeline();
  let _: () = pipeline.incr("foo").await?; // returns when the command is queued in memory
  let _: () = pipeline.incr("foo").await?; // returns when the command is queued in memory

  assert_eq!(pipeline.last::<i64>().await?, 2);
  // pipelines can also be reused
  assert_eq!(pipeline.last::<i64>().await?, 4);
  Ok(())
}

Trait Implementations§

Source§

impl Debug for Ctx

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Ctx

Source§

type Target = Pipeline<Client>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl Freeze for Ctx

§

impl !RefUnwindSafe for Ctx

§

impl Send for Ctx

§

impl Sync for Ctx

§

impl Unpin for Ctx

§

impl !UnwindSafe for Ctx

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V