diff --git a/docs/src/content/docs/commands/GET.md b/docs/src/content/docs/commands/GET.md index e4cd3f9a0..bcff5aa33 100644 --- a/docs/src/content/docs/commands/GET.md +++ b/docs/src/content/docs/commands/GET.md @@ -4,9 +4,9 @@ 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 @@ -14,29 +14,38 @@ 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