Skip to content

Commit

Permalink
#844: docs: update GET docs (#875)
Browse files Browse the repository at this point in the history
Co-authored-by: Jyotinder Singh <[email protected]>
  • Loading branch information
sebzz2k2 and JyotinderSingh authored Oct 2, 2024
1 parent 5ae8e58 commit c9dd4e1
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions docs/src/content/docs/commands/GET.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,48 @@ description: The `GET` command in DiceDB is used to retrieve the value of a spec
---

The `GET` command in DiceDB is used to retrieve the value of a specified key. If the key exists, the value is written and
if it does not then the command returns `nil`. This is one of the most fundamental operations in DiceDB.
if it does not then the command returns `nil` and an error is returned if the value stored at key is not a string. This is one of the most fundamental operations in DiceDB.

## Synopsis
## Syntax

```bash
GET key
```

## Parameters

- `key`: The name of the key whose value you want to retrieve. The key is a string, and it is required for the GET command to execute.
| Parameter | Description | Type | Required |
|-----------|--------------------------------------------------------------------------|--------|----------|
| key | The name of the key whose value you want to retrieve. The key is a string.| string | Yes |

## Return Value
## Return Values

- `String`: If the specified key exists and holds a string value, the GET command returns the value stored at the key.
- `nil`: If the specified key does not exist, the command returns `nil`.
- `Error`: If the specified key exists but is not a string, an error is returned.
| Condition | Return Value |
|--------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| The specified key exists and holds a string value | The string value stored at the key. |
| The specified key does not exist | `nil` |
| The specified key exists but is not a string, or multiple keys are passed | error |

## Behaviour

When the GET command is issued, DiceDB checks the existence of the specified key:

1. `Key Exists and Holds a String`: The value associated with the key is retrieved and returned.
2. `Key Does Not Exist`: The command returns `nil`.
2. `Key Does Not Exist`: The command returns `nil`
3. `Key Exists but Holds a Non-string Value`: An error is raised indicating that the operation against that key is not permitted.
4. `Multiple Keys Passed`: If multiple keys are passed to the GET command, an error is raised, as the command only accepts a single key at a time.

The GET command is a read-only operation and does not modify the state of the DiceDB database.

## Error Handling
## Errors
1. **Expected string but got another type:**
- Error Message: (error) ERR expected string but got another type
- Occurs when the specified key holds a value that is not a string (e.g., a list, set, hash, or zset). DiceDB uses strict type checking to ensure that the correct type of operation is performed on the appropriate data type.

The GET command can raise the following errors:

- `WRONGTYPE Operation against a key holding the wrong kind of value`: This error is returned if the specified key holds a value that is not a string (e.g., a list, set, hash, or zset). DiceDB uses strict type checking to ensure that the correct type of operation is performed on the appropriate data type.
2. **Wrong number of arguments for 'GET' command:**
- Error Message: (error) ERR wrong number of arguments for 'get' command
- Occurs when multiple keys are passed as parameters.


## Example Usage

Expand Down

0 comments on commit c9dd4e1

Please sign in to comment.