You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: course-definition.yml
+53-6Lines changed: 53 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -3629,7 +3629,34 @@ stages:
3629
3629
name: "Failures within transactions"
3630
3630
difficulty: medium
3631
3631
description_md: |
3632
-
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
3632
+
In this stage, you'll add support for handling failures within a transaction.
3633
+
3634
+
### Failures within transactions
3635
+
3636
+
When executing a transaction, if a command fails, the error is captured and returned within the response for `EXEC`. All other commands in
3637
+
the transaction are still executed.
3638
+
3639
+
You can read more about this behaviour [in the official Redis docs](https://redis.io/docs/latest/develop/interact/transactions/#errors-inside-a-transaction).
3640
+
3641
+
Example:
3642
+
3643
+
```bash
3644
+
$ redis-cli
3645
+
> MULTI
3646
+
OK
3647
+
> SET foo xyz
3648
+
QUEUED
3649
+
> INCR foo
3650
+
QUEUED
3651
+
> SET bar 7
3652
+
> EXEC
3653
+
1) OK
3654
+
2) (error) ERR value is not an integer or out of range
3655
+
3) OK
3656
+
```
3657
+
3658
+
In the example above, note that the error for the `INCR` command was returned as the second array element. The third command (`SET bar 7`) was
3659
+
still executed successfully.
3633
3660
3634
3661
### Tests
3635
3662
@@ -3642,21 +3669,41 @@ stages:
3642
3669
The tester will then connect to your server as a Redis client, and send multiple commands using the same connection:
3643
3670
3644
3671
```bash
3645
-
$ redis-cli SET foo abc
3646
-
> SET bar 7
3672
+
$ redis-cli
3673
+
> SET foo abc
3674
+
OK
3675
+
> SET bar 41
3676
+
OK
3647
3677
> MULTI
3678
+
OK
3648
3679
> INCR foo
3680
+
QUEUED
3649
3681
> INCR bar
3682
+
QUEUED
3650
3683
> EXEC
3684
+
1) (error) ERR value is not an integer or out of range
3685
+
2) (integer) 42
3651
3686
```
3652
3687
3653
-
The tester will then create another connection to your server as a Redis client, and send a single command:
3688
+
The expected response for `EXEC` is a [RESP array](https://redis.io/docs/latest/develop/reference/protocol-spec/#arrays) of
3689
+
the responses of the queued commands. The exact bytes will be:
3654
3690
3655
3691
```bash
3656
-
$ redis-cli GET foo
3657
-
> GET bar
3692
+
*2\r\n-ERR value is not an integer or out of range\r\n:42\r\n
3693
+
```
3694
+
3695
+
The tester will also verify that the last command was successfully executed and that the key `bar` exists:
3696
+
3697
+
```bash
3698
+
$ redis-cli
3699
+
> GET foo (expecting "$3\r\nabc\r\n" as the response)
3700
+
> GET bar (expecting "$2\r\n42\r\n" as the response)
3658
3701
```
3659
3702
3703
+
### Notes
3704
+
3705
+
- There are a subset of command failures (like syntax errors) that will cause a transaction to be aborted entirely. We won't
3706
+
cover those in this challenge.
3660
3707
marketing_md: |
3661
3708
In this stage, you'll implement handling failures while executing a transaction.
0 commit comments