Function l337_redis::async_transaction
source · pub async fn async_transaction<C, K, T, F, Args>(
con: &mut C,
keys: &[K],
args: &mut Args,
func: F
) -> RedisResult<T>where
C: ConnectionLike,
K: ToRedisArgs,
F: for<'a> FnMut(&'a mut C, &'a mut Pipeline, &'a mut Args) -> BoxFuture<'a, RedisResult<Option<T>>>,
Expand description
Rewite of redis::transaction for use with an async connection. It is assumed that the fn’s return value will be the return value of Pipeline::query_async. Returning None from this fn will cause it to be re-run, as that is the value returned from Pipeline::query_async when run in atomic mode, and the watched keys are modified somewhere else.
use redis::AsyncCommands;
use futures::prelude::*;
let key = "the_key";
let mut count = 0i32;
let (new_val,) : (isize,) = l337_redis::async_transaction(&mut con, &[key], &mut count, |con, pipe, count_ref| async move {
*count_ref += 1;
let old_val : isize = con.get(key).await?;
pipe
.set(key, old_val + 1).ignore()
.get(key)
.query_async(con)
.await
}.boxed()).await?;
println!("The incremented number is: {}", new_val);