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
+151-30
Original file line number
Diff line number
Diff line change
@@ -3458,7 +3458,32 @@ stages:
3458
3458
name: "Queueing commands"
3459
3459
difficulty: medium
3460
3460
description_md: |
3461
-
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
3461
+
In this stage, you'll add support for queuing commands within a transaction.
3462
+
3463
+
### Queuing commands
3464
+
3465
+
After [MULTI](https://redis.io/docs/latest/commands/multi/) is executed, any further commands
3466
+
from a connection are queued until [EXEC](https://redis.io/docs/latest/commands/exec/) is executed.
3467
+
3468
+
The response to all of these commands is `+QUEUED\r\n` (That's `QUEUED` encoded as a [Simple String](https://redis.io/docs/latest/develop/reference/protocol-spec/#simple-strings)).
3469
+
3470
+
Example:
3471
+
3472
+
```bash
3473
+
$ redis-cli
3474
+
> MULTI
3475
+
OK
3476
+
> SET foo 41
3477
+
QUEUED
3478
+
> INCR foo
3479
+
QUEUED
3480
+
3481
+
... (and so on, until EXEC is executed)
3482
+
```
3483
+
3484
+
When commands are queued, they should not be executed or alter the database in any way.
3485
+
3486
+
In the example above, until `EXEC` is executed, the key `foo` will not exist.
3462
3487
3463
3488
### Tests
3464
3489
@@ -3471,17 +3496,18 @@ stages:
3471
3496
The tester will then connect to your server as a Redis client, and send multiple commands using the same connection:
3472
3497
3473
3498
```bash
3474
-
$ redis-cli MULTI
3475
-
> SET foo 41
3476
-
> INCR foo
3499
+
$ redis-cli
3500
+
> MULTI
3501
+
> SET foo 41 (expecting "+QUEUED\r\n")
3502
+
> INCR foo (expecting "+QUEUED\r\n")
3477
3503
```
3478
3504
3479
-
The tester will then create another connection to your master as a Redis client, and send a single command:
3505
+
Since these commands were only "queued", the key `foo` should not exist yet. The tester will verify this by creating
3506
+
another connection and sending this command:
3480
3507
3481
3508
```bash
3482
-
$ redis-cli GET foo
3509
+
$ redis-cli GET foo (expecting `$-1\r\n` as the response)
3483
3510
```
3484
-
3485
3511
marketing_md: |
3486
3512
In this stage, you'll implement queueing commands to a transaction.
3487
3513
@@ -3490,7 +3516,31 @@ stages:
3490
3516
name: "Executing a transaction"
3491
3517
difficulty: hard
3492
3518
description_md: |
3493
-
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
3519
+
In this stage, you'll add support for executing a transaction that contains multiple commands.
3520
+
3521
+
### Executing a transaction
3522
+
3523
+
When the [EXEC](https://redis.io/docs/latest/commands/exec/) command is sent within a transaction,
3524
+
all commands queued in that transaction are executed.
3525
+
3526
+
The response to [EXEC](https://redis.io/docs/latest/commands/exec/) is an array of the responses of the queued commands.
3527
+
3528
+
Example:
3529
+
3530
+
```bash
3531
+
$ redis-cli
3532
+
> MULTI
3533
+
OK
3534
+
> SET foo 41
3535
+
QUEUED
3536
+
> INCR foo
3537
+
QUEUED
3538
+
> EXEC
3539
+
1) OK
3540
+
2) (integer) 42
3541
+
```
3542
+
3543
+
In the above example, `OK` is the response of the `SET` command, and `42` is the response of the `INCR` command.
3494
3544
3495
3545
### Tests
3496
3546
@@ -3504,19 +3554,20 @@ stages:
3504
3554
3505
3555
```bash
3506
3556
$ redis-cli MULTI
3507
-
> SET foo 6
3508
-
> INCR foo
3509
-
> INCR bar
3510
-
> GET bar
3511
-
> EXEC
3557
+
> SET foo 6 (expecting "+QUEUED\r\n")
3558
+
> INCR foo (expecting "+QUEUED\r\n")
3559
+
> INCR bar (expecting "+QUEUED\r\n")
3560
+
> GET bar (expecting "+QUEUED\r\n")
3561
+
> EXEC (expecting an array of responses for the queued commands)
3512
3562
```
3513
3563
3514
-
The tester will then create another connection to your server as a Redis client, and send a single command:
3564
+
Since the transaction was executed, the key `foo` should exist and have the value `7`.
3565
+
3566
+
The tester will verify this by running a GET command:
3515
3567
3516
3568
```bash
3517
-
$ redis-cli GET foo
3569
+
$ redis-cli GET foo (expecting "7" encoded as a bulk string)
3518
3570
```
3519
-
3520
3571
marketing_md: |
3521
3572
In this stage, you'll implement executing a successful transaction.
3522
3573
@@ -3525,7 +3576,30 @@ stages:
3525
3576
name: "The DISCARD command"
3526
3577
difficulty: easy
3527
3578
description_md: |
3528
-
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
3579
+
In this stage, you'll add support for the DISCARD command.
3580
+
3581
+
### The DISCARD command
3582
+
3583
+
[DISCARD](https://redis.io/docs/latest/commands/discard/) is used to abort a transactions. It discards all commands queued in a transaction,
3584
+
and returns `+OK\r\n`.
3585
+
3586
+
Example:
3587
+
3588
+
```bash
3589
+
$ redis-cli
3590
+
> MULTI
3591
+
OK
3592
+
> SET foo 41
3593
+
QUEUED
3594
+
> DISCARD
3595
+
OK
3596
+
> DISCARD
3597
+
(error) ERR DISCARD without MULTI
3598
+
```
3599
+
3600
+
In the above example, note that the first `DISCARD` returns `OK`, but the second `DISCARD` returns an error since the transaction was aborted.
3601
+
3602
+
### DISCARD
3529
3603
3530
3604
### Tests
3531
3605
@@ -3538,13 +3612,13 @@ stages:
3538
3612
The tester will then connect to your server as a Redis client, and send multiple commands using the same connection:
3539
3613
3540
3614
```bash
3541
-
$ redis-cli MULTI
3542
-
> SET foo 41
3543
-
> INCR foo
3544
-
> DISCARD
3545
-
> GET foo
3546
-
> GET bar
3547
-
> DISCARD
3615
+
$ redis-cli
3616
+
> MULTI
3617
+
> SET foo 41 (expecting "+QUEUED\r\n")
3618
+
> INCR foo (expecting "+QUEUED\r\n")
3619
+
> DISCARD (expecting "+OK\r\n")
3620
+
> GET foo (expecting "$-1\r\n" as the response)
3621
+
> DISCARD (expecting "-ERR DISCARD without MULTI\r\n" as the response)
3548
3622
```
3549
3623
3550
3624
marketing_md: |
@@ -3555,7 +3629,34 @@ stages:
3555
3629
name: "Failures within transactions"
3556
3630
difficulty: medium
3557
3631
description_md: |
3558
-
**🚧 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.
3559
3660
3560
3661
### Tests
3561
3662
@@ -3568,21 +3669,41 @@ stages:
3568
3669
The tester will then connect to your server as a Redis client, and send multiple commands using the same connection:
3569
3670
3570
3671
```bash
3571
-
$ redis-cli SET foo abc
3572
-
> SET bar 7
3672
+
$ redis-cli
3673
+
> SET foo abc
3674
+
OK
3675
+
> SET bar 41
3676
+
OK
3573
3677
> MULTI
3678
+
OK
3574
3679
> INCR foo
3680
+
QUEUED
3575
3681
> INCR bar
3682
+
QUEUED
3576
3683
> EXEC
3684
+
1) (error) ERR value is not an integer or out of range
3685
+
2) (integer) 42
3577
3686
```
3578
3687
3579
-
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:
3580
3690
3581
3691
```bash
3582
-
$ redis-cli GET foo
3583
-
> GET bar
3692
+
*2\r\n-ERR value is not an integer or out of range\r\n:42\r\n
3584
3693
```
3585
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)
3701
+
```
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.
3586
3707
marketing_md: |
3587
3708
In this stage, you'll implement handling failures while executing a transaction.
0 commit comments