Skip to content

Commit

Permalink
Merge pull request #222 from codecrafters-io/add-transactions-docs
Browse files Browse the repository at this point in the history
Add support for INCR command and update course definition
  • Loading branch information
rohitpaulk authored Jun 19, 2024
2 parents fa8a14e + 44febc7 commit 85c84f4
Showing 1 changed file with 65 additions and 10 deletions.
75 changes: 65 additions & 10 deletions course-definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3163,16 +3163,37 @@ stages:
name: "The INCR command (1/3)"
difficulty: easy
description_md: |
In this stage, you'll add support for handling the `INCR` command when a key exists with numerical value.
In this stage, you'll add support for the `INCR` command.
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
### The INCR command
The [INCR](https://redis.io/docs/latest/commands/incr/) command is used to increment the value of a key by 1.
Example usage:
```bash
$ redis-cli SET foo 5
"OK"
$ redis-cli INCR foo
(integer) 6
$ redis-cli INCR foo
(integer) 7
```
If the key doesn't exist, the value will be set to 1.
We'll split the implementation of this command into three stages:
- Key exists and has a numerical value (**This stage**)
- Key doesn't exist (later stages)
- Key exists but doesn't have a numerical value (later stages)
### Tests
The tester will execute your program like this:
```
./spawn_redis_server.sh
```bash
$ ./spawn_redis_server.sh
```
The tester will then connect to your server as a Redis client and run the following commands:
Expand All @@ -3192,14 +3213,29 @@ stages:
description_md: |
In this stage, you'll add support for handling the `INCR` command when a key does not exist.
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
### Recap
The implementation of [`INCR`](https://redis.io/docs/latest/commands/incr/) is split into three stages:
- Key exists and has a numerical value (previous stages)
- Key doesn't exist (**This stage**)
- Key exists but doesn't have a numerical value (later stages)
When a key doesn't exit, `INCR` sets the value to 1. Example:
```bash
$ redis-cli INCR missing_key
(integer) 1
$ redis-cli GET missing_key
"1"
```
### Tests
The tester will execute your program like this:
```
./spawn_redis_server.sh
```bash
$ ./spawn_redis_server.sh
```
The tester will then connect to your server as a Redis client and run the following commands:
Expand All @@ -3209,6 +3245,10 @@ stages:
> INCR foo (expecting ":1\r\n" as the response)
> INCR bar (expecting ":1\r\n" as the response)
```
### Notes
- Your implementation still needs to pass the tests in the previous stage.
marketing_md: |
In this stage, you'll continue implementing the INCR command.
Expand All @@ -3219,14 +3259,29 @@ stages:
description_md: |
In this stage, you'll add support for handling the `INCR` command when a key exists but doesn't have a numerical value.
**🚧 We're still working on instructions for this stage**. You can find notes on how the tester works below.
### Recap
The implementation of [`INCR`](https://redis.io/docs/latest/commands/incr/) is split into three stages:
- Key exists and has a numerical value (previous stages)
- Key doesn't exist (previous stages)
- Key exists but doesn't have a numerical value (**This stage**)
When a key exists but doesn't have a numerical value, `INCR` will return an error. Example:
```bash
$ redis-cli SET foo xyz
"OK"
$ redis-cli INCR foo
-ERR value is not an integer or out of range
```
### Tests
The tester will execute your program like this:
```
./spawn_redis_server.sh
```bash
$ ./spawn_redis_server.sh
```
The tester will then connect to your server as a Redis client and run the following commands:
Expand Down

0 comments on commit 85c84f4

Please sign in to comment.