Skip to content

Commit 8d1beb4

Browse files
committed
Add support for handling failures within transactions in course-definition.yml.
1 parent b247b8f commit 8d1beb4

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

course-definition.yml

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,7 +3629,34 @@ stages:
36293629
name: "Failures within transactions"
36303630
difficulty: medium
36313631
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.
36333660
36343661
### Tests
36353662
@@ -3642,21 +3669,41 @@ stages:
36423669
The tester will then connect to your server as a Redis client, and send multiple commands using the same connection:
36433670
36443671
```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
36473677
> MULTI
3678+
OK
36483679
> INCR foo
3680+
QUEUED
36493681
> INCR bar
3682+
QUEUED
36503683
> EXEC
3684+
1) (error) ERR value is not an integer or out of range
3685+
2) (integer) 42
36513686
```
36523687
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:
36543690
36553691
```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)
36583701
```
36593702
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.
36603707
marketing_md: |
36613708
In this stage, you'll implement handling failures while executing a transaction.
36623709

0 commit comments

Comments
 (0)