rustis/commands/transaction_commands.rs
1use crate::{
2 client::{prepare_command, PreparedCommand},
3 resp::{cmd, SingleArg, SingleArgCollection},
4};
5
6/// A group of Redis commands related to Transactions
7/// # See Also
8/// [Redis Generic Commands](https://redis.io/commands/?group=transactions)
9pub trait TransactionCommands<'a> {
10 /// Marks the given keys to be watched for conditional execution of a transaction.
11 ///
12 /// # See Also
13 /// [<https://redis.io/commands/watch/>](https://redis.io/commands/watch/)
14 #[must_use]
15 fn watch<K, KK>(self, keys: KK) -> PreparedCommand<'a, Self, ()>
16 where
17 Self: Sized,
18 K: SingleArg,
19 KK: SingleArgCollection<K>,
20 {
21 prepare_command(self, cmd("WATCH").arg(keys))
22 }
23
24 /// Flushes all the previously watched keys for a transaction.
25 ///
26 /// If you call [`execute`](crate::client::Transaction::execute),
27 /// there's no need to manually call UNWATCH.
28 ///
29 /// # See Also
30 /// [<https://redis.io/commands/unwatch/>](https://redis.io/commands/unwatch/)
31 #[must_use]
32 fn unwatch(self) -> PreparedCommand<'a, Self, ()>
33 where
34 Self: Sized,
35 {
36 prepare_command(self, cmd("UNWATCH"))
37 }
38}