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§
Methods from Deref<Target = Pipeline<Client>>§
Sourcepub async fn all<R>(&self) -> Result<R, Error>where
R: FromValue,
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(())
}Sourcepub async fn try_all<R>(&self) -> Vec<Result<R, Error>>where
R: FromValue,
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(())
}Sourcepub async fn last<R>(&self) -> Result<R, Error>where
R: FromValue,
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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