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
In this stage, you'll add support for calculating the distance between two locations using the `GEODIST`comamnd.
1
+
In this stage, you'll add support for calculating the distance between two locations using the `GEODIST`command.
2
2
3
3
### The `GEODIST` command
4
-
The `GEODIST` command returns the distance between two members of a key. The default unit of the distance which is returned, is meters.
4
+
5
+
The `GEODIST` command returns the distance between two members of a key.
5
6
6
7
Example usage:
7
8
@@ -10,50 +11,44 @@ Example usage:
10
11
"682477.7582"
11
12
```
12
13
13
-
It returns the distance as a string, encoded as a RESP Bulk String.
14
+
The distance is returned in meters, encoded as a [RESP bulk string](https://redis.io/docs/latest/develop/reference/protocol-spec/#bulk-strings).
14
15
15
16
Redis uses the [Haversine's Formula](https://en.wikipedia.org/wiki/Haversine_formula#Example) to calculate the distance between two points. You can see how this is done in the Redis source code [here](https://github.com/redis/redis/blob/4322cebc1764d433b3fce3b3a108252648bf59e7/src/geohash_helper.c#L228C1-L228C72).
16
17
17
18
### Tests
19
+
18
20
The tester will execute your program like this:
21
+
19
22
```bash
20
23
$ ./your_program.sh
21
24
```
22
25
23
-
It will add multiple locations using the `GEOADD` command.
26
+
It will then add multiple locations using the `GEOADD` command:
27
+
24
28
```bash
25
29
$ redis-cli
26
30
> GEOADD places 11.5030378 48.164271 "Munich"
27
31
> GEOADD places 2.2944692 48.8584625 "Paris"
28
32
```
29
33
30
-
The tester will then send multiple `GEODIST` commands specifying two locations. For example, the tester might send your program a command like this:
34
+
The tester will then send multiple `GEODIST` commands specifying two locations:
31
35
32
36
```bash
33
37
> GEODIST places Munich Paris
34
38
# Expecting "682477.7582"
35
39
```
36
40
37
-
The value is a RESP bulk string encoded as:
41
+
The tester will validate that the response is a RESP bulk string that contains the distance between the two locations, for example:
38
42
39
-
```
40
-
$11\r\n
41
-
682477.7582\r\n
43
+
```bash
44
+
$11\r\n682477.7582\r\n
42
45
```
43
46
44
47
### Notes
45
-
- The tester will be lenient when validating the distance returned by the `GEODIST` command. The distance should match the actual distance between the provided locations with a precision of **up to 2 decimal places after rounding**.
46
-
47
-
* This means that minor floating-point differences are acceptable as long as the values, when rounded to two decimal places, are the same.
48
-
49
-
* For example, if the expected distance is `12345.67`, any of the following returned values will be accepted:
50
-
51
-
*`12345.67001`
52
-
*`12345.674`
53
-
*`12345.6659`
54
-
*`12345.6666`
55
-
*`12345.669`
56
-
57
-
* However, values like `12345.64`, `12345.70`, or `12345.61` would be considered incorrect.
58
48
59
-
- If one or both of the location specified in the `GEODIST` command does not exist, it should return a null bulk string `($-1\r\n)`.
49
+
- The distance should match the actual distance between the provided locations with a precision of **up to 2 decimal places after rounding**. For example, if the expected distance is `12345.67`, any of the following returned values will be accepted:
0 commit comments