Cohesive helpers built on top of redis-rs for:
get
ing and set
ing json valuesA macro that helps you set up a safe async redis transaction.
Takes:
WATCH
EXEC
component of the atomic pipeline fails), then the body will be re-executed.```rust tx!(&mut con, pipe, &["key1"], { let mut value: u8 = con.get("key1").await?; value = value + 1;
Ok(pipe.set("key1", value)) }); ```
```rust tx!(&mut con, pipe, &["key1"], { let mut value: u8 = con.get("key1").await?; value = value + 1;
if value == 69 { return Err(Abort(BadNumberFound)); }
Ok(pipe.set("key1", value)) }); ```
```rust
let tx: Result
if value == 69 { return Err(Abort(BadNumberFound)); }
Ok(pipe.set("key1", value)) }); ```
Ok(T)
of tx
is the type that's handed to pipe.set()
for redis-rs
's type inference.TxError
allows you to return any type in TxError::Abort
for custom type handling.redis
error or serde
tx
will reflect this in the
associated TxError::DbError
or TxError::Serialization
. Using the helpers from TODO allow you to turn this:
rust
let json_string: String = con.get(key).await?;
let value: Type = serde_json::from_str(&json_string).unwrap;
rust
let value: Type = con.json_get(key).await.unwrap();