Skip to content

Commit

Permalink
Docs: Updated GETDEL DOCS #779 (#936)
Browse files Browse the repository at this point in the history
  • Loading branch information
surya0180 authored Oct 5, 2024
1 parent b52dc11 commit 0ff573c
Showing 1 changed file with 45 additions and 45 deletions.
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.

0 comments on commit 0ff573c

Please sign in to comment.