Crates.io | redis_utils |
lib.rs | redis_utils |
version | 0.1.3 |
source | src |
created_at | 2022-01-18 02:33:50.511271 |
updated_at | 2022-02-17 21:37:36.88056 |
description | Cohesive helpers built on top of redis-rs |
homepage | |
repository | |
max_upload_size | |
id | 515902 |
size | 15,617 |
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.tx!(&mut con, pipe, &["key1"], {
let mut value: u8 = con.get("key1").await?;
value = value + 1;
Ok(pipe.set("key1", value))
});
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))
});
let tx: Result<u8, TxError<NumberError> > = 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))
});
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:
let json_string: String = con.get(key).await?;
let value: Type = serde_json::from_str(&json_string).unwrap;
let value: Type = con.json_get(key).await.unwrap();