-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
3,766 additions
and
802 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ dicedb | |
venv | ||
__pycache__ | ||
.idea/ | ||
./dice | ||
*.rdb | ||
dice | ||
|
||
# build output | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.