Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1018 Migration: Append_GetRange #1095

Merged
merged 31 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
30702b7
migrated GETRANGE from eval.go to store_eval.go, modified all the tes…
bhima2001 Oct 14, 2024
a2f8697
resolved merge conflicts
bhima2001 Oct 14, 2024
9ebf440
made some lint changes, also resolved some conflicts becuase of pulli…
bhima2001 Oct 15, 2024
6e42989
Merge branch 'master' of github.com:bhima2001/dice into migrate-appen…
bhima2001 Oct 15, 2024
7307eff
modified testcases based on the function called to run the testcases …
bhima2001 Oct 15, 2024
9d34fa7
migrated append to store_eval.go, added this command ion cmd_meta als…
bhima2001 Oct 15, 2024
75921cc
Merge branch 'master' of github.com:bhima2001/dice into migrate-appen…
bhima2001 Oct 16, 2024
2dba81a
modified a unit testcase
bhima2001 Oct 16, 2024
65beb57
added test cases for both append and getrange in HTTP, resp, async an…
bhima2001 Oct 16, 2024
7b1f301
added cmdType for append
bhima2001 Oct 16, 2024
acac1ae
modified APPEND and also added http test cases for GET RANGE
bhima2001 Oct 17, 2024
5b3a3c6
resolved merge conflicts
bhima2001 Oct 17, 2024
cc9e940
removed apppend_test.go from async, also modified variables
bhima2001 Oct 17, 2024
b3a09a1
removed the async/getrange_test.go
bhima2001 Oct 18, 2024
0ba35f1
Merge branch 'master' of github.com:bhima2001/dice into migrate-appen…
bhima2001 Oct 18, 2024
455333c
modified websockets assert package
bhima2001 Oct 18, 2024
823796d
Merge branch 'DiceDB:master' into migrate-append-getRange
bhima2001 Oct 19, 2024
4f0078b
resolved conflicts with the master branch
bhima2001 Oct 19, 2024
e8eed50
added docs for both getrange and append
bhima2001 Oct 19, 2024
490bee8
Merge branch 'migrate-append-getRange' of github.com:bhima2001/dice i…
bhima2001 Oct 19, 2024
5ec96be
modified a typo in docs
bhima2001 Oct 20, 2024
c0171ff
modifed the testing package and also added clean up for all the tests
bhima2001 Oct 20, 2024
263dbf3
modified the arity for getrange and append
bhima2001 Oct 20, 2024
8e04343
resolved merge conflictrs
bhima2001 Oct 20, 2024
d927082
made changes in getrange DOCs
bhima2001 Oct 20, 2024
6671f0b
Merge branch 'master' into migrate-append-getRange
bhima2001 Oct 20, 2024
03cacf1
resolved merge conflicts
bhima2001 Oct 20, 2024
3059719
merging after resolving conflicts
bhima2001 Oct 20, 2024
8a68b13
resolved merge conflicts
bhima2001 Oct 20, 2024
88b0115
Update docs/src/content/docs/commands/GETRANGE.MD
apoorvyadav1111 Oct 21, 2024
804e9e8
Update docs/src/content/docs/commands/GETRANGE.MD
apoorvyadav1111 Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions docs/src/content/docs/commands/APPEND.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
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.

## Syntax

```bash
APPEND key value
```

## Parameters
| Parameter | Description | Type | Required |
|-----------|---------------------------------------------------------------------------|---------|----------|
| `key` | The name of the key to be set. | String | Yes |
| `value` | The value to be set for the key. | String | Yes |

## Return values

| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| if key is set successfully | length of the string. |

## Behaviour
- If the specified key does not exist, the `APPEND` command will create a new key-value pair.
- If the specified key already exists, the `APPEND` command will append the value to the existing value of the key.


## Errors
1. `Wrong type of value or key`:

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

2. `Invalid syntax or conflicting options`:

- Error Message: `(error) ERROR wrong number of arguments for 'append' command`
- If the number of arguments are not exactly equal to 2.

## Example Usage

### Basic Usage

Setting a key `foo` with the value `bar` using `APPEND`

```bash
127.0.0.1:7379> APPEND foo bar
(integer) 3
```

Appending to key `foo` that contains `bar` with `baz`

```bash
127.0.0.1:7379> SET foo bar
127.0.0.1:7379> APPEND foo baz
(integer) 6
```

### Invalid usage

Trying to use `APPEND` without giving the value

```bash
127.0.0.1:7379> APPEND foo
(error) ERROR wrong number of arguments for 'append' command
```
Trying to use `APPEND` on a invalid data type.
```bash
127.0.0.1:7379> LPUSH foo bar
127.0.0.1:7379> APPEND foo baz
(error) ERROR WRONGTYPE Operation against a key holding the wrong kind of value
```
107 changes: 107 additions & 0 deletions docs/src/content/docs/commands/GETRANGE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: GETRANGE
description: The `GETRANGE` command in DiceDB is used to get a substring of a string, provided the start and end indices
---
The `GETRANGE` command in DiceDB is used to get a substring of a string, provided the start and end indices.

## Syntax

```bash
GETRANGE key start end
```

## Parameters
| Parameter | Description | Type | Required |
|-----------|---------------------------------------------------------------------------|---------|----------|
| `key` | The name of the key to be set. | String | Yes |
apoorvyadav1111 marked this conversation as resolved.
Show resolved Hide resolved
apoorvyadav1111 marked this conversation as resolved.
Show resolved Hide resolved
| `start` | The starting index of the required substring. | Integer | Yes |
| `end` | The ending index of the required substring. | Integer | Yes |
## Return values

| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| if key contains a valid string | a substring based on the start and end indices |
| if `start` is greater than `end` | an empty string is returned |
| if the `end` exceeds the length of the string present at `key` | the entire string is returned |
| if the `start` is greater than the length of the string | an empty string is returned. |

## Behaviour
- If the specified key does not exist, the `GETRANGE` command returns an empty string.
- If `start` is greater than `end`, the `GETRANGE` command returns an empty string.
- If `start` is not within the length of the string, the `GETRANGE` command returns an empty string.
- `start` and `end` can be negative which removed `end + 1` characters from the other side of the string.
apoorvyadav1111 marked this conversation as resolved.
Show resolved Hide resolved
- Both `start` and `end` can be negative, which removes characters from the string, starting from the `end + 1` position on the right.

## Errors
1. `Wrong type of value or key`:

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

2. `Invalid syntax or conflicting options`:

- Error Message: `(error) ERROR wrong number of arguments for 'GETRANGE' command`
- If the number of arguments are not exactly equal to 4.

3. `Invalid input type for start and end`

- Error Message: `(error) ERROR value is not an integer or out of range`
- If `start` and `end` are not integers.

## Example Usage

### Basic Usage

Assume we have a string stored in `foo`

```bash
127.0.0.1:7379> SET foo apple
OK
```

```bash
127.0.0.1:7379> GETRANGE foo 1 3
"ppl"
```

```bash
127.0.0.1:7379> GETRANGE foo 0 -1
"apple"
```

```bash
127.0.0.1:7379> GETRANGE foo 0 -10
""
```

```bash
127.0.0.1:7379> GETRANGE foo 0 -2
"appl"
```

```bash
127.0.0.1:7379> GETRANGE foo 0 1001
"apple"
```

### Invalid usage

Trying to use `GETRANGE` without giving the value

```bash
127.0.0.1:7379> GETRANGE foo
(error) ERROR wrong number of arguments for 'getrange' command
```

Trying to use `GETRANGE` on an invalid data type..
apoorvyadav1111 marked this conversation as resolved.
Show resolved Hide resolved

```bash
127.0.0.1:7379> LPUSH foo apple
127.0.0.1:7379> GETRANGE foo 0 5
(error) ERROR WRONGTYPE Operation against a key holding the wrong kind of value
```

```bash
127.0.0.1:7379> GETRANGE foo s e
(error) ERROR value is not an integer or out of range
```
86 changes: 0 additions & 86 deletions integration_tests/commands/async/append_test.go

This file was deleted.

104 changes: 104 additions & 0 deletions integration_tests/commands/http/append_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package http

import (
"testing"

testifyAssert "github.com/stretchr/testify/assert"
)

func TestAPPEND(t *testing.T) {
exec := NewHTTPCommandExecutor()
testCases := []struct {
name string
commands []HTTPCommand
expected []interface{}
cleanup []HTTPCommand
}{
{
name: "APPEND and GET a new Val",
commands: []HTTPCommand{
{Command: "APPEND", Body: map[string]interface{}{"key": "k", "value": "newVal"}},
{Command: "GET", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{float64(6), "newVal"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "k"}},
},
},
{
name: "APPEND to an exisiting key and GET",
commands: []HTTPCommand{
{Command: "SET", Body: map[string]interface{}{"key": "k", "value": "Bhima"}},
{Command: "APPEND", Body: map[string]interface{}{"key": "k", "value": "Shankar"}},
{Command: "GET", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{"OK", float64(12), "BhimaShankar"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "k"}},
},
},
{
name: "APPEND without input value",
commands: []HTTPCommand{
{Command: "APPEND", Body: map[string]interface{}{"key": "k"}},
},
expected: []interface{}{"ERR wrong number of arguments for 'append' command"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "k"}},
},
},
{
name: "APPEND empty string to an exsisting key with empty string",
commands: []HTTPCommand{
{Command: "SET", Body: map[string]interface{}{"key": "k", "value": ""}},
{Command: "APPEND", Body: map[string]interface{}{"key": "k", "value": ""}},
},
expected: []interface{}{"OK", float64(0)},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "k"}},
},
},
{
name: "APPEND to key created using LPUSH",
commands: []HTTPCommand{
{Command: "LPUSH", Body: map[string]interface{}{"key": "m", "value": "bhima"}},
{Command: "APPEND", Body: map[string]interface{}{"key": "m", "value": "shankar"}},
},
expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "m"}},
},
},
{
name: "APPEND value with leading zeros",
commands: []HTTPCommand{
{Command: "APPEND", Body: map[string]interface{}{"key": "z", "value": "0043"}},
},
expected: []interface{}{float64(4)},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "z"}},
},
},
{
name: "APPEND to key created using SADD",
commands: []HTTPCommand{
{Command: "SADD", Body: map[string]interface{}{"key": "key", "value": "apple"}},
{Command: "APPEND", Body: map[string]interface{}{"key": "key", "value": "banana"}},
},
expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "key"}},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {

for i, cmd := range tc.commands {
result, _ := exec.FireCommand(cmd)
testifyAssert.Equal(t, tc.expected[i], result)
}
exec.FireCommand(tc.cleanup[0])
})
}
}
Loading