redis_driver/commands/transaction_commands.rs
1use crate::{
2 resp::{cmd, CommandArg, SingleArgOrCollection},
3 prepare_command, PreparedCommand,
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 {
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>(&mut self, keys: KK) -> PreparedCommand<Self, ()>
16 where
17 Self: Sized,
18 K: Into<CommandArg>,
19 KK: SingleArgOrCollection<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::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(&mut self) -> PreparedCommand<Self, ()>
33 where
34 Self: Sized,
35 {
36 prepare_command(self, cmd("UNWATCH"))
37 }
38}