redis_utils
Cohesive helpers built on top of redis-rs for:
- async transactions
geting andseting json values
Async Transactions
A macro that helps you set up a safe async redis transaction.
Takes:
- A connection
- The name of a pipeline which it configures in atomic-mode.
- A set of keys to
WATCH - The body of the transaction that can get those keys, use the pipeline (for side effects) and if those keys change (and
the
EXECcomponent of the atomic pipeline fails), then the body will be re-executed. - Allows for safe early returns (aborted transactions) with typed values, all keys will be un-watched during an early return.
tx!;
Aborting a tx
tx!;
Handling return values
let tx: = tx!;
- The
Ok(T)oftxis the type that's handed topipe.set()forredis-rs's type inference. TxErrorallows you to return any type inTxError::Abortfor custom type handling.- If the transaction fails due to an underlying
rediserror orserdetxwill reflect this in the associatedTxError::DbErrororTxError::Serialization.
JSON helpers
Using the helpers from TODO allow you to turn this:
let json_string: String = con.get.await?;
let value: Type = from_str.unwrap;
let value: Type = con.json_get.await.unwrap;