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

#1022 Command Migration: ('HEXISTS', 'HKEYS', 'HVALS') #1087

Merged
merged 37 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6680fe2
migrated hexists
tarungka Oct 10, 2024
4982f5b
update: migrated evalKEYS
tarungka Oct 13, 2024
8d333d8
update: migrated hvals
tarungka Oct 14, 2024
5b26075
update: test cases
tarungka Oct 14, 2024
e84b741
reafactor: format and remove unecessary comments
tarungka Oct 15, 2024
14f5394
fix: eval tests
tarungka Oct 15, 2024
b4b8ff0
fix: command responses
tarungka Oct 15, 2024
6d2c34c
fix: test cases
tarungka Oct 17, 2024
da1e0d3
feat: add test case
tarungka Oct 17, 2024
5d9c5d6
feat: added integration tests for hkeys, hvals and hexists
tarungka Oct 17, 2024
793597f
feat: integration tests for http and ws
tarungka Oct 17, 2024
c506ec7
fix: integration test cases
tarungka Oct 17, 2024
ea52a01
chore: lint
tarungka Oct 17, 2024
7a5f829
refactor: remove unecessary comments
tarungka Oct 17, 2024
2993fc4
feat: migrated tests for hkeys and hexists
tarungka Oct 22, 2024
c8fae0d
feat: migrated test cases for kvals
tarungka Oct 22, 2024
46ad65f
fix: integration tests hexists
tarungka Oct 22, 2024
8ee9e3f
feat: added a test case for hexists
tarungka Oct 22, 2024
2093645
chore: merge upstream master and resolve conflicts
tarungka Oct 23, 2024
670cfe2
chore: merge upstream master and resolve conflicts
tarungka Oct 23, 2024
0975c25
fix: eval.go
tarungka Oct 23, 2024
ac4cc88
fix: integration tests
tarungka Oct 23, 2024
d89305a
fix: integration tests
tarungka Oct 23, 2024
2084a49
fix: integration tests
tarungka Oct 23, 2024
b67bdce
fix: more integration tests
tarungka Oct 23, 2024
80891e0
fix: integration tests
tarungka Oct 23, 2024
22d167f
fix: integration tests
tarungka Oct 24, 2024
e3c8296
fix: unit tests
tarungka Oct 24, 2024
c50a959
chore: delete migrated test cases
tarungka Oct 25, 2024
fe7c29f
feat: update the assert package
tarungka Oct 25, 2024
16c6053
fix: unittests
tarungka Oct 26, 2024
41bc1ce
fix: merge conflicts
tarungka Oct 26, 2024
9316e88
chore: format the code
tarungka Oct 26, 2024
af367d4
add docs for hexists
tarungka Oct 28, 2024
660b7cf
add docs for hkeys and hvals
tarungka Oct 28, 2024
39454c0
fix: docs
tarungka Oct 28, 2024
40cecb1
fix merge conflicts
tarungka Oct 28, 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
86 changes: 86 additions & 0 deletions docs/hexists_command_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: HEXISTS
description: The `HEXISTS` command in DiceDB checks if a specified field exists within a hash stored at a given key. This command is used to verify the presence of a field within hash data structures, making it essential for conditional logic.
---

The `HEXISTS` command in DiceDB checks if a specified field exists within a hash stored at a given key. This command is used to verify the presence of a field within hash data structures, making it essential for conditional logic.

## Syntax

```bash
HEXISTS key field
```

## Parameters

| Parameter | Description | Type | Required |
|-----------|------------------------------------|--------|----------|
| `key` | The name of the key holding a hash | String | Yes |
| `field` | The field to check within the hash | String | Yes |

## Return values

| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| If the field exists within the hash | `1` |
| If the field does not exist within the hash | `0` |

## Behaviour

- The `HEXISTS` command checks if the specified `field` exists within the hash stored at `key`.
- If the specified `field` is present in the hash, `HEXISTS` returns `1`.
- If the specified `field` is not present or if `key` does not contain a hash, it returns `0`.
- If `key` does not exist, `HEXISTS` returns `0`.

## Errors

1. `Non-hash type or wrong data type`:

- Error Message: `(error) WRONGTYPE Operation against a key holding the wrong kind of value`
- Occurs if `key` holds a non-hash data structure, such as a string or list.

2. `Invalid syntax or missing parameter`:

- Error Message: `(error) ERR syntax error`
- Occurs if the syntax is incorrect or required parameters (`key` and `field`) are missing.

## Example Usage

### Basic Usage

Checking if field `name` exists in the hash stored at key `user:1001`

```bash
127.0.0.1:7379> HEXISTS user:1001 name
1
```

If the field `name` is not present

```bash
127.0.0.1:7379> HEXISTS user:1001 age
0
```

### Checking non-existent key

If the hash `user:1002` does not exist:

```bash
127.0.0.1:7379> HEXISTS user:1002 name
0
```

## Best Practices

- `Check for Field Existence`: Use `HEXISTS` to check for a field’s existence in conditional logic, especially if subsequent commands depend on the field's presence.

## Alternatives

- `HGET`: The `HGET` command retrieves the value of a specified field within a hash. However, unlike `HEXISTS`, it returns `nil` if the field does not exist, rather than a boolean response.

## Notes

- If `key` is not of type hash, consider using commands specifically designed for other data types.

By utilizing the `HEXISTS` command, you can conditionally manage hash data in DiceDB, verifying field presence before performing operations based on field existence.
88 changes: 88 additions & 0 deletions docs/hkeys_command_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: HKEYS
description: The `HKEYS` command in DiceDB retrieves all fields in a hash stored at a given key. This command is essential for working with hash data structures, enabling retrieval of all field names for dynamic inspection or iteration.
---

The `HKEYS` command in DiceDB retrieves all fields in a hash stored at a given key. This command is essential for working with hash data structures, enabling retrieval of all field names for dynamic inspection or iteration.

## Syntax

```bash
HKEYS key
```

## Parameters

| Parameter | Description | Type | Required |
|-----------|------------------------------------|--------|----------|
| `key` | The name of the key holding a hash | String | Yes |

## Return values

| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| If the key exists and holds a hash | Array of field names |
| If the key does not exist or is empty | Empty array `[]` |

## Behaviour

- The `HKEYS` command retrieves all field names within the hash stored at the specified `key`.
- If the hash is empty or the `key` does not exist, it returns an empty array `[]`.
- If `key` exists but does not hold a hash, an error is returned.

## Errors

1. `Non-hash type or wrong data type`:

- Error Message: `(error) WRONGTYPE Operation against a key holding the wrong kind of value`
- Occurs if `key` holds a non-hash data structure, such as a string or list.

2. `Missing required parameter`:

- Error Message: `(error) ERR wrong number of arguments for 'HKEYS' command`
- Occurs if the `key` parameter is missing from the command.

## Example Usage

### Basic Usage

Retrieving all field names in the hash stored at key `user:1001`

```bash
127.0.0.1:7379> HKEYS user:1001
1) "name"
2) "age"
3) "email"
```

### Empty hash

If the hash stored at `user:1002` exists but has no fields:

```bash
127.0.0.1:7379> HKEYS user:1002
(nil)
```

### Non-existent key

If the hash `user:1003` does not exist:

```bash
127.0.0.1:7379> HKEYS user:1003
(nil)
```

## Best Practices

- `Use Before Iterating`: Use `HKEYS` to retrieve field names in dynamic applications where the field names may not be predetermined.

## Alternatives

- `HGETALL`: The `HGETALL` command retrieves all field-value pairs in a hash as an array, rather than only the field names.

## Notes

- Ensure that `key` is of type hash before using `HKEYS`, as other data types will produce errors.

Using the `HKEYS` command, you can efficiently access all field names in hash structures, making it a valuable tool for dynamic data inspection in DiceDB.
88 changes: 88 additions & 0 deletions docs/hvals_command_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
title: HVALS
description: The `HVALS` command in DiceDB retrieves all values in a hash stored at a given key. This command allows you to access only the values within a hash, which is helpful for data inspection or retrieval without needing the field names.
---

The `HVALS` command in DiceDB retrieves all values in a hash stored at a given key. This command allows you to access only the values within a hash, which is helpful for data inspection or retrieval without needing the field names.

## Syntax

```bash
HVALS key
```

## Parameters

| Parameter | Description | Type | Required |
|-----------|------------------------------------|--------|----------|
| `key` | The name of the key holding a hash | String | Yes |

## Return values

| Condition | Return Value |
|------------------------------------------------|---------------------------------------------------|
| If the key exists and holds a hash | Array of values within the hash |
| If the key does not exist or is empty | Empty array `[]` |

## Behaviour

- The `HVALS` command retrieves all values stored in the hash at the specified `key`, without returning the associated field names.
- If the hash is empty or `key` does not exist, it returns an empty array `[]`.
- If `key` exists but does not contain a hash, an error is returned.

## Errors

1. `Non-hash type or wrong data type`:

- Error Message: `(error) WRONGTYPE Operation against a key holding the wrong kind of value`
- Occurs if `key` holds a non-hash data structure, such as a string or list.

2. `Missing required parameter`:

- Error Message: `(error) ERR wrong number of arguments for 'HVALS' command`
- Occurs if the `key` parameter is missing from the command.

## Example Usage

### Basic Usage

Retrieving all values in the hash stored at key `user:1001`

```bash
127.0.0.1:7379> HVALS user:1001
1) "John Doe"
2) "30"
3) "john@example.com"
```

### Empty hash

If the hash stored at `user:1002` exists but has no fields:

```bash
127.0.0.1:7379> HVALS user:1002
(nil)
```

### Non-existent key

If the hash `user:1003` does not exist:

```bash
127.0.0.1:7379> HVALS user:1003
(nil)
```

## Best Practices

- `Use for Values Only`: Use `HVALS` when only the values within a hash are needed without requiring field names, simplifying value extraction.

## Alternatives

- `HGETALL`: The `HGETALL` command retrieves all field-value pairs in a hash, providing both names and values.

## Notes

- Ensure `key` is a hash type to avoid errors when using `HVALS`.

Using the `HVALS` command enables efficient access to all values within a hash structure in DiceDB, simplifying data retrieval when field names are unnecessary.
Loading