Skip to content

Commit

Permalink
Merge branch 'master' into watch
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh committed Oct 6, 2024
2 parents f20957b + 402db3c commit 9efd40b
Show file tree
Hide file tree
Showing 65 changed files with 3,766 additions and 802 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/full-test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,26 @@ name: dice-test-suite
on:
push:
branches: [master]
paths-ignore:
- "**.md"
- "docs/**"
- ".github/**"
- "**.txt"
- "**.json"
- "**.yaml"
- "**.yml"
- "LICENSE"
pull_request:
branches: [master]
paths-ignore:
- "**.md"
- "docs/**"
- ".github/**"
- "**.txt"
- "**.json"
- "**.yaml"
- "**.yml"
- "LICENSE"

jobs:
build:
Expand All @@ -22,4 +40,4 @@ jobs:
- name: Run Unit tests
run: make unittest
- name: Run Integration tests
run: make test
run: make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ dicedb
venv
__pycache__
.idea/
./dice
*.rdb
dice

# build output
Expand Down
10 changes: 9 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
EvictAllKeysRandom = "allkeys-random"
EvictAllKeysLRU = "allkeys-lru"
EvictAllKeysLFU = "allkeys-lfu"

DefaultKeysLimit int = 200000000
)

var (
Expand All @@ -44,6 +46,8 @@ var (
FileLocation = utils.EmptyStr

InitConfigCmd = false

KeysLimit = DefaultKeysLimit
)

type Config struct {
Expand Down Expand Up @@ -114,7 +118,7 @@ var baseConfig = Config{
MaxMemory: 0,
EvictionPolicy: EvictAllKeysLFU,
EvictionRatio: 0.9,
KeysLimit: 200000000,
KeysLimit: DefaultKeysLimit,
AOFFile: "./dice-master.aof",
PersistenceEnabled: true,
WriteAOFOnCleanup: false,
Expand Down Expand Up @@ -293,6 +297,10 @@ func mergeFlagsWithConfig() {
if Port != DefaultPort {
DiceConfig.Server.Port = Port
}

if KeysLimit != DefaultKeysLimit {
DiceConfig.Server.KeysLimit = KeysLimit
}
}

// This function checks if the config file is present or not at ConfigFileLocation
Expand Down
90 changes: 45 additions & 45 deletions docs/src/content/docs/commands/GETDEL.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
---
title: GETDEL
description: Documentation for the DiceDB command GETDEL
description: The `GETDEL` command in DiceDB is used to retrieve the value of a specified key and then delete the key from the database. This command is useful when you need to fetch a value and ensure that it is removed from the database in a single atomic operation.
---

The `GETDEL` command in DiceDB is used to retrieve the value of a specified key and then delete the key from the database. This command is useful when you need to fetch a value and ensure that it is removed from the database in a single atomic operation.

## Syntax

```plaintext
```
GETDEL key
```

## Parameters

- `key`: The key whose value you want to retrieve and delete. This parameter is a string and must be a valid key in the DiceDB database.
| Parameter | Description | Type | Required |
|-----------|---------------------------------------------------------------------------|---------|----------|
| `key` | The key whose value you want to retrieve and delete. | String | Yes |

## Return Value
## Return values

- `String`: If the key exists, the command returns the value associated with the key.
- `nil`: If the key does not exist, the command returns `nil`.
| Condition | Return Value |
|----------------------|------------------------------------------------------------------|
| Key exists | `String`: The command returns the value associated with the key. |
| Key does not exist | `nil`: The command returns `nil`. |

## Behaviour

When the `GETDEL` command is executed, the following steps occur:
1. The command checks if the specified key exists in the DiceDB database.
2. If the key exists, the value associated with the key is retrieved.
3. The key is then deleted from the database.
4. The retrieved value is returned to the client.
5. If the key does not exist, `nil` is returned, and no deletion occurs.

1. The command checks if the specified key exists in the DiceDB database.
2. If the key exists, the value associated with the key is retrieved.
3. The key is then deleted from the database.
4. The retrieved value is returned to the client.
5. If the key does not exist, `nil` is returned, and no deletion occurs.

## Error Handling
## Errors

The `GETDEL` command can raise errors in the following scenarios:

1. `Wrong Type Error`: If the key exists but is not a string (e.g., it is a list, set, hash, etc.), a `WRONGTYPE` error will be raised.
2. `Syntax Error`: If the command is called without the required parameter, a syntax error will be raised.
1. `Wrong Type Error`:

## Example Usage
- Error Message: `ERROR WRONGTYPE Operation against a key holding the wrong kind of value`
- Occurs if the key exists but is not a string (e.g., it is a list, set, hash, etc.).

### Example 1: Key Exists
2. `Syntax Error`:

```plaintext
SET mykey "Hello, World!"
GETDEL mykey
```
- Error Message: `ERROR wrong number of arguments for 'getdel' command`
- Occurs if the command is called without the required parameter.

`Output:`
## Examples

```plaintext
### Example with Existent key

```bash
127.0.0.1:7379> SET mykey "Hello, World!"
OK
127.0.0.1:7379> GETDEL mykey
"Hello, World!"
127.0.0.1:7379> GET mykey
(nil)
```

`Explanation:`
`Explanation:`

- The key `mykey` is set with the value `"Hello, World!"`.
- The `GETDEL` command retrieves the value `"Hello, World!"` and deletes the key `mykey` from the database.
- The `GET` command attempts to retrieve the value associated with the key `mykey` and returns `nil` as the key no longer exists.

### Example 2: Key Does Not Exist
### Example with a Non-Existent Key

```plaintext
GETDEL nonexistingkey
```

`Output:`

```plaintext
```bash
127.0.0.1:7379> GETDEL nonexistingkey
(nil)
```

`Explanation:`
`Explanation:`

- The key `nonexistingkey` does not exist in the database.
- The `GETDEL` command returns `nil` since the key is not found.

### Example 3: Key of Wrong Type

```plaintext
LPUSH mylist "item1"
GETDEL mylist
```

`Output:`
### Example with a Wrong Type of Key

```plaintext
(error) WRONGTYPE Operation against a key holding the wrong kind of value
```bash
127.0.0.1:7379> LPUSH mylist "item1"
(integer) 1
127.0.0.1:7379> GETDEL mylist
ERROR WRONGTYPE Operation against a key holding the wrong kind of value
```

`Explanation:`
`Explanation:`

- The key `mylist` is a list, not a string.
- The `GETDEL` command raises a `WRONGTYPE` error because it expects the key to be a string.
- The `GETDEL` command raises a `WRONGTYPE` error because it expects the key to be a string.
135 changes: 56 additions & 79 deletions docs/src/content/docs/commands/JSON.CLEAR.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,116 +3,93 @@ title: JSON.CLEAR
description: Documentation for the DiceDB command JSON.CLEAR
---

The `JSON.CLEAR` command is part of the DiceDBJSON module, which allows you to manipulate JSON data stored in DiceDB. This command is used to clear the value at a specified path in a JSON document, effectively setting it to an empty state. This can be particularly useful when you want to reset a part of your JSON document without removing the key itself.
The `JSON.CLEAR` command allows you to manipulate JSON data stored in DiceDB. This command is used to clear the value at a specified path in a JSON document, effectively setting it to an empty state. This can be particularly useful when you want to reset a part of your JSON document without removing the key itself.

## Syntax

```
JSON.CLEAR key [path]
```

## Parameters

- `key`: (String) The key under which the JSON document is stored.
- `path`: (String) The path within the JSON document that you want to clear. The path should be specified in JSONPath format. If the path is omitted, the root path (`$`) is assumed.
| Parameter | Description | Type | Required |
|-----------|---------------------------------------------------------------------------|---------|----------|
| `key` | (String) The key under which the JSON document is stored. | String | Yes |
| `path` | (String) The path within the JSON document that you want to clear. The path should be specified in JSONPath format. If the path is omitted, the root path (`$`) is assumed. | String | No |

## Return Value
## Return values

- `Integer`: The number of paths that were cleared.
| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| Command is successful | `Integer` (The number of paths that were cleared) |
| Syntax or specified constraints are invalid | error |

## Behaviour

When the `JSON.CLEAR` command is executed, it traverses the JSON document stored at the specified key and clears the value at the given path. The clearing operation depends on the type of the value at the path:

- For objects, it removes all key-value pairs.
- For arrays, it removes all elements.
- For strings, it sets the value to an empty string.
- For strings, the value remaines unchanged.
- For numbers, it sets the value to `0`.
- For booleans, it sets the value to `false`.
- For booleans, the value remaines unchanged.

If the specified path does not exist, the command does nothing and returns `0`.

## Error Handling
## Errors

The `JSON.CLEAR` command can raise the following errors:

- `(error) ERR wrong number of arguments for 'json.clear' command`: This error is raised if the command is called with an incorrect number of arguments.
- `(error) ERR key does not exist`: This error is raised if the specified key does not exist in the DiceDB database.
- `(error) ERR path is not a valid JSONPath`: This error is raised if the specified path is not a valid JSONPath expression.
- `(error) ERR path does not exist`: This error is raised if the specified path does not exist within the JSON document.

## Example Usage
- `(error) ERR could not perform this operation on a key that doesn't exist`: This error is raised if the specified key does not exist in the DiceDB database.
- `(error) ERR invalid JSONPath`: This error is raised if the specified path is not a valid JSONPath expression.
- `(error) ERR Existing key has wrong Dice type`: This error is raised if the key exists but the value is not of the expected JSON type and encoding.

### Example 1: Clearing a JSON Object

Suppose you have a JSON document stored under the key `user:1001`:

```json
{
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "Anytown"
}
}
```

To clear the `address` object, you would use the following command:

```sh
JSON.CLEAR user:1001 $.address
```
Note: If the specified path does not exist within the JSON document, the command will not raise an error but will simply not modify anything.

After executing this command, the JSON document would be:

```json
{
"name": "John Doe",
"age": 30,
"address": {}
}
```

### Example 2: Clearing an Array

Suppose you have a JSON document stored under the key `user:1002`:

```json
{
"name": "Jane Doe",
"hobbies": ["reading", "swimming", "hiking"]
}
```

To clear the `hobbies` array, you would use the following command:

```sh
JSON.CLEAR user:1002 $.hobbies
```
## Example Usage

After executing this command, the JSON document would be:
### Clearing a JSON Object

```json
{
"name": "Jane Doe",
"hobbies": []
}
```bash
127.0.0.1:7379> JSON.SET user:1001 $ '{"name": "John Doe", "age": 30, "address": {"street": "123 Main St", "city": "Anytown"}}'
OK
127.0.0.1:7379> JSON.CLEAR user:1001 $.address
(integer) 1
127.0.0.1:7379> JSON.GET user:1001
"{\"name\":\"John Doe\",\"age\":30,\"address\":{}}"
```

### Example 3: Clearing the Root Path

Suppose you have a JSON document stored under the key `user:1003`:
### Clearing a Number

```json
{
"name": "Alice",
"age": 25
}
```bash
127.0.0.1:7379> JSON.SET user:1001 $ '{"name": "John Doe", "age": 30, "address": {"street": "123 Main St", "city": "Anytown"}}'
OK
127.0.0.1:7379> JSON.CLEAR user:1001 $.age
(integer) 1
127.0.0.1:7379> JSON.GET user:1001
"{\"name\":\"John Doe\",\"age\":0,\"address\":{\"street\":\"123 Main St\",\"city\":\"Anytown\"}}"
```

To clear the entire JSON document, you would use the following command:
### Clearing an Array

```sh
JSON.CLEAR user:1003
```bash
127.0.0.1:7379> JSON.SET user:1002 $ '{"name": "Jane Doe", "hobbies": ["reading", "swimming", "hiking"]}'
OK
127.0.0.1:7379> JSON.CLEAR user:1002 $.hobbies
(integer) 1
127.0.0.1:7379> JSON.GET user:1002
"{\"name\":\"Jane Doe\",\"hobbies\":[]}"
```

After executing this command, the JSON document would be:
### Clearing the Root Path

```json
{}
```bash
127.0.0.1:7379> JSON.SET user:1003 $ '{"name": "Alice", "age": 25}'
OK
127.0.0.1:7379> JSON.CLEAR user:1003
(integer) 1
127.0.0.1:7379> JSON.GET user:1003
"{}"
```
Loading

0 comments on commit 9efd40b

Please sign in to comment.