Skip to content

Commit

Permalink
Improved transactions documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcatanzariti committed Dec 5, 2022
1 parent ea85904 commit ff9116d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@ async fn main() -> Result<()> {
assert_eq!("mymessage", payload);
}
pub_sub_stream.close().await?;
Ok(())
}
```
Expand All @@ -354,7 +356,7 @@ Once the stream has been created, it is still possible to add addtional subscrip
by calling [`subscribe`](PubSubStream::subscribe), [`psubscribe`](PubSubStream::psubscribe)
or [`ssubscribe`](PubSubStream::ssubscribe) on the [`PubSubStream`](PubSubStream) instance
### Example
#### Example
```
use rustis::{
Expand All @@ -377,6 +379,8 @@ async fn main() -> Result<()> {
// 3nd subscription (possibility to mix all the kinds of subscription)
pub_sub_stream.psubscribe("o*").await?;
pub_sub_stream.close().await?;
Ok(())
}
```
Expand Down
34 changes: 34 additions & 0 deletions src/client/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ impl Transaction {
self.forget_flags.push(true);
}

/// Execute the transaction by the sending the queued command
/// as a whole batch to the Redis server.
///
/// # Return
/// It is the caller responsability to use the right type to cast the server response
/// to the right tuple or collection depending on which command has been
/// [queued](BatchPreparedCommand::queue) or [forgotten](BatchPreparedCommand::forget).
///
/// The most generic type that can be requested as a result is `Vec<resp::Value>`
///
/// # Example
/// ```
/// use rustis::{
/// client::{Client, Transaction, BatchPreparedCommand},
/// commands::StringCommands,
/// resp::{cmd, Value}, Result,
/// };
///
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// let mut client = Client::connect("127.0.0.1:6379").await?;
///
/// let mut transaction = client.create_transaction();
///
/// transaction.set("key1", "value1").forget();
/// transaction.set("key2", "value2").forget();
/// transaction.get::<_, String>("key1").queue();
/// let value: String = transaction.execute().await?;
///
/// assert_eq!("value1", value);
///
/// Ok(())
/// }
/// ```
pub async fn execute<T: FromValue>(mut self) -> Result<T> {
self.queue(cmd("EXEC"));

Expand Down

0 comments on commit ff9116d

Please sign in to comment.