Skip to content

Commit

Permalink
Merge branch 'master' into feature/watch_label
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh committed Nov 17, 2024
2 parents 3372159 + f2267bd commit b47eafe
Show file tree
Hide file tree
Showing 22 changed files with 1,053 additions and 313 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/full-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,19 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: dorny/paths-filter@v3
id: file_types
with:
filters: |
watch_file_changes:
- '**/*.go'
- name: Install dependencies
run: go get -v . # Check if there is any version changes from the cache
- name: Build
run: make build
- name: Run Unit tests
if: steps.file_types.outputs.watch_file_changes == 'true'
run: make unittest
- name: Run Integration tests
run: make test
if: steps.file_types.outputs.watch_file_changes == 'true'
run: make test
11 changes: 8 additions & 3 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golint-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golint-
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
Expand Down
28 changes: 27 additions & 1 deletion docs/src/content/docs/commands/APPEND.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: APPEND
description: The `APPEND` command in DiceDB is used to either set the value of a key or append a value to an existing key. This command allows for both creating and updating key-value pairs.
---

The `APPEND` command in DiceDB is used to either set the value of a key or append a value to an existing key. This command allows for both creating and updating key-value pairs.
The `APPEND` command in DiceDB is used to either set the value of a key or append a value to an existing key and returns the length of the value stored at the specified key after appending. This command allows for both creating and updating key-value pairs.

## Syntax

Expand Down Expand Up @@ -56,8 +56,34 @@ Appending to key `foo` that contains `bar` with `baz`

```bash
127.0.0.1:7379> SET foo bar
OK
127.0.0.1:7379> APPEND foo baz
(integer) 6
127.0.0.1:7379> GET foo
"barbaz"
```

Appending "1" to key `bmkey` that contains a bitmap equivalent of `42`

```bash
127.0.0.1:7379> SETBIT bmkey 2 1
(integer) 0
127.0.0.1:7379> SETBIT bmkey 3 1
(integer) 0
127.0.0.1:7379> SETBIT bmkey 5 1
(integer) 0
127.0.0.1:7379> SETBIT bmkey 10 1
(integer) 0
127.0.0.1:7379> SETBIT bmkey 11 1
(integer) 0
127.0.0.1:7379> SETBIT bmkey 14 1
(integer) 0
127.0.0.1:7379> GET bmkey
"42"
127.0.0.1:7379> APPEND bmkey 1
(integer) 3
127.0.0.1:7379> GET bmkey
"421"
```

### Invalid usage
Expand Down
90 changes: 90 additions & 0 deletions docs/src/content/docs/commands/GEOADD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: GEOADD
description: The `GEOADD` command in DiceDB is used to add geospatial items (longitude,latitude) to a specified key, storing them as a sorted set. This would allow for efficient querying of geographical data using commands like GEOSEARCH.
---

The `GEOADD` command in DiceDB is used to add geospatial items (longitude,latitude) to a specified key, storing them as a sorted set. This would allow for efficient querying of geographical data using commands like GEOSEARCH.

## Syntax

```bash
GEOADD key [NX | XX] [CH] longitude latitude member [longitude latitude member ...]
```

## Parameters

| Parameter | Description | Type | Required |
| --------- | --------------------------------------------------------------------------------- | ------ | -------- |
| key | The name of the sorted set where the geospatial data will be stored. | string | Yes |
| NX | Only add new elements; do not update existing ones. | NONE | No |
| XX | Only update existing elements; do not add new ones. | NONE | No |
| longitude | longitude of the location (must be between -180 and 180 degrees). | float | Yes |
| latitude | latitude of the location (must be between -85.05112878 and 85.05112878 degrees). | float | Yes |
| member | A unique identifier for the location. | string | Yes |


## Return Values

| Condition | Return Value |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| For each new member added. | 1 |
| No new member is added. | 0 |
| Incorrect Argument Count |`ERR wrong number of arguments for 'geoadd' command` |
| If the longitude is not a valid number or is out of range. |`ERR invalid longitude` |
| If the latitude is not a valid number or is out of range. |`ERR invalid latitude` |

## Behaviour

When the GEOADD command is issued, DiceDB performs the following steps:

1. It checks whether longitude and latitude are valid or not. If not an error is thrown.
2. It checks whether the set exists or not.
3. If set doesn't exist new set is created or else the same set is used.
4. It adds or updates the member in the set.
5. It returns number of members added.

## Errors

1.`Wrong number of arguments for 'GEOADD' command`
- Error Message: (error) ERR wrong number of arguments for 'geoadd' command.
- Occurs when the command is executed with an incorrect number of arguments.

2. `Longitude not a valid number or is out of range `
- Error Message: (error) ERR invalid longitude.
- Occurs when longitude is out of range(-180 to 180) or not a valid number.

3. `Latitude not a valid number or is out of range `
- Error Message: (error) ERR invalid latitude.
- Occurs when latitude is out of range(-85.05112878 to 85.05112878) or not a valid number.

## Example Usage

Here are a few examples demonstrating the usage of the GEOADD command:

### Example : Adding new member to a set

```bash
127.0.0.1:7379> GEOADD locations 13.361389 38.115556 "Palermo"
1
```

### Example : Updating an already existing member to a set

```bash
127.0.0.1:7379> GEOADD locations 13.361389 39.115556 "Palermo"
0
```

### Example : Error Adding a member with invalid longitude

```bash
127.0.0.1:7379> GEOADD locations 181.120332 39.115556 "Jamaica"
(error) ERROR invalid longitude
```

### Example : Error Adding a member with invalid latitde

```bash
127.0.0.1:7379> GEOADD locations 13.361389 91.115556 "Venice"
(error) ERROR invalid latitude
```
71 changes: 71 additions & 0 deletions docs/src/content/docs/commands/GEODIST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
title: GEODIST
description: The `GEODIST` command in Redis is used to calculate the distance between two members (geospatial points) stored in a geospatial index(set).
---

The `GEODIST` command in DiceDB is used to calculate the distance between two members (geospatial points) stored in a geospatial index(set).

## Syntax

```bash
GEODIST key member1 member2 [m | km | ft | mi]
```

## Parameters

| Parameter | Description | Type | Required |
| --------- | --------------------------------------------------------------------------------- | ------ | -------- |
| key | The name of the sorted set where the geospatial data is stored. | string | Yes |
| member1 | The name of the member1 from where you want to measure the distance. | string | Yes |
| member2 | The name of the member2 to where you want to measure the distance. | string | Yes |
| m | The distance to be measured in meters. | NONE | NO |
| km | The distance to be measured in kilometers. | NONE | NO |
| ft | The distance to be measured in feet. | NONE | NO |
| mi | The distance to be measured in miles. | NONE | NO |


## Return Values

| Condition | Return Value |
| ------------------------------------------------------------ | ----------------------------------------------------------- |
| If both members exist in the set with no option | distance b/w them in meters |
| If both members exist in the set with option km | distance b/w them in kilometers |
| If both members exist in the set with option ft | distance b/w them in feet |
| If both members exist in the set with option mi | distance b/w them in miles |
| If any member doesn't exist in Set | nil |
| Incorrect Argument Count |`ERR wrong number of arguments for 'geodist' command` |

## Behaviour

When the GEODIST command is issued, DiceDB performs the following steps:

1. It gets the sorted set(key).
2. It gets the scores(geohashes) from the sorted sets for both the members.
3. It calculates the distance bw them and returns it.

## Errors

1.`Wrong number of arguments for 'GEODIST' command`
- Error Message: (error) ERR wrong number of arguments for 'geodist' command.
- Occurs when the command is executed with an incorrect number of arguments.


## Example Usage

Here are a few examples demonstrating the usage of the GEODIST command:

### Example : Adding new member to a set

```bash
127.0.0.1:7379> GEOADD cities -74.0060 40.7128 "New York"
1
127.0.0.1:7379> GEOADD cities -79.3470 43.6510 "Toronto"
1
127.0.0.1:7379> GEODIST cities "New York" "Toronto"
"548064.1868"
127.0.0.1:7379> GEODIST cities "New York" "Toronto km"
"548.0642"
127.0.0.1:7379> GEODIST cities "New York" "Toronto mi"
"340.5521"
```

123 changes: 123 additions & 0 deletions docs/src/content/docs/commands/ZADD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
title: ZADD
description: The ZADD command adds one or more members with scores to a sorted set in DiceDB. If the key doesn't exist, it creates a new sorted set. If a member already exists, its score is updated. This command is essential for managing sorted data efficiently.
---

The ZADD command in DiceDB is used to add one or more members with their associated scores to a sorted set. If the specified key doesn't exist, it creates a new sorted set. For existing members, their scores are updated. This command is crucial for maintaining ordered data structures efficiently.

## Syntax

```bash
ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score member ...]
```

## Parameters

| Parameter | Description | Type | Required |
| --------- | ----------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `key` | The key of the sorted set | String | Yes |
| `score` | The score associated with the member | Float | Yes |
| `member` | The member to be added to the sorted set | String | Yes |
| `NX` | Only add new elements. Don't update existing elements. | Flag | No |
| `XX` | Only update existing elements. Don't add new elements. | Flag | No |
| `GT` | Only update existing elements if the new score is greater than the current score | Flag | No |
| `LT` | Only update existing elements if the new score is less than the current score | Flag | No |
| `CH` | Modify the return value from the number of new elements added, to the total number of elements changed | Flag | No |
| `INCR` | When this option is specified, ZADD acts like ZINCRBY. Only one score-element pair can be specified in this mode. | Flag | No |

## Return values

| Condition | Return Value |
| ------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ |
| Command executed successfully | The number of elements added to the sorted set (not including elements already existing for which the score was updated) |
| Key holds a value that is not a sorted set | Error message |

## Behaviour

- If the key does not exist, a new sorted set is created and the specified members are added with their respective scores.
- If a specified member already exists in the sorted set, its score is updated to the new score provided.
- Members are always added in sorted order according to their score, from the lowest to the highest.
- If multiple score-member pairs are specified, they are processed left to right.
- The `NX` and `XX` options are mutually exclusive and cannot be used together.
- When `CH` is specified, the command returns the total number of elements changed (added and updated).
- The `INCR` option allows the command to behave like ZINCRBY, incrementing the existing score of a member (or setting it if it doesn't exist).

## Errors

1. `Wrong type of value or key`:

- Error Message: `(error) WRONGTYPE Operation against a key holding the wrong kind of value`
- Occurs when attempting to use ZADD on a key that contains a non-sorted set value.

2. `Invalid score`:
- Error Message: `(error) ERR value is not an integer or a float`
- Occurs when the provided score is not a valid floating-point number.

## Example Usage

### Basic Usage

```bash
127.0.0.1:7379> ZADD myzset 1 "one" 2 "two" 3 "three"
(integer) 3
127.0.0.1:7379> ZADD myzset 4 "four"
(integer) 1
```

### Updating Existing Members

```bash
127.0.0.1:7379> ZADD myzset 5 "two"
(integer) 0
```

### Using NX Option

```bash
127.0.0.1:7379> ZADD myzset NX 6 "six" 7 "two"
(integer) 1
```

### Using XX Option

```bash
127.0.0.1:7379> ZADD myzset XX 8 "eight" 9 "two"
(integer) 0
```

### Using CH Option

```bash
127.0.0.1:7379> ZADD myzset CH 10 "ten" 11 "two"
(integer) 2
```

### using INCR Option

```bash
127.0.0.1:7379> ZADD myzset INCR 1 "two"
(integer) 12
```

## Invalid Usage

```bash
127.0.0.1:7379> ZADD myzset NX XX 12 "twelve"
(error) ERR XX and NX options at the same time are not compatible
```

```bash
127.0.0.1:7379> ZADD myzset LT GT 15 "twelve"
(error) ERR GT, LT, and/or NX options at the same time are not compatible
```

## Best Practices

- Use appropriate score values to maintain the desired order of elements in the sorted set.
- Consider using the `NX` or `XX` options when you want to specifically add new elements or update existing ones, respectively.
- Use the `CH` option when you need to know the total number of elements changed, including both additions and updates.

## Notes

- The time complexity of ZADD is O(log(N)) for each item added, where N is the number of elements in the sorted set.
- Scores can be any double-precision floating-point number.
17 changes: 17 additions & 0 deletions integration_tests/commands/http/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ func TestAPPEND(t *testing.T) {
{Command: "del", Body: map[string]interface{}{"key": "myzset"}},
},
},
{
name: "APPEND to key created using SETBIT",
commands: []HTTPCommand{
{Command: "SETBIT", Body: map[string]interface{}{"key": "bitkey", "values": []string{"2", "1"}}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "bitkey", "values": []string{"3", "1"}}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "bitkey", "values": []string{"5", "1"}}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "bitkey", "values": []string{"10", "1"}}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "bitkey", "values": []string{"11", "1"}}},
{Command: "SETBIT", Body: map[string]interface{}{"key": "bitkey", "values": []string{"14", "1"}}},
{Command: "APPEND", Body: map[string]interface{}{"key": "bitkey", "value": "1"}},
{Command: "GET", Body: map[string]interface{}{"key": "bitkey"}},
},
expected: []interface{}{float64(0), float64(0), float64(0), float64(0), float64(0), float64(0), float64(3), "421"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "bitkey"}},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
Loading

0 comments on commit b47eafe

Please sign in to comment.