# DELEX

> Delete a key, or delete it only when its string value meets a condition.

URL: https://docs.hotkv.com/commands/delex/

```
DELEX key [IFEQ value | IFNE value | IFDEQ digest | IFDNE digest]
```

- Group: String
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`DELEX` deletes `key`. With a condition it deletes the key only when the
string stored there meets it, which lets you release a lock or an expiring
token without deleting a value that someone else has written since you read
it. Without a condition it deletes the key whatever it holds.

## Options

| Option | Deletes the key when |
| --- | --- |
| `IFEQ value` | the string equals `value` |
| `IFNE value` | the string does not equal `value` |
| `IFDEQ digest` | the [DIGEST](https://docs.hotkv.com/commands/digest/index.md) of the string equals `digest` |
| `IFDNE digest` | the digest of the string does not equal `digest` |

## Return value

Integer `1` if the key was deleted, `0` if it did not exist or the condition
was not met, in RESP2 and RESP3. A condition without its argument, or no key,
is `ERR wrong number of arguments for 'delex' command`.

## Examples

```
127.0.0.1:6379> SET session:1 token-a
OK
127.0.0.1:6379> DELEX session:1 IFEQ token-b
(integer) 0
127.0.0.1:6379> DELEX session:1 IFNE token-a
(integer) 0
127.0.0.1:6379> DELEX session:1 IFEQ token-a
(integer) 1
127.0.0.1:6379> DELEX session:1
(integer) 0
127.0.0.1:6379> SET session:1 token-a
OK
127.0.0.1:6379> DELEX session:1 IFDNE 0123456789abcdef
(integer) 1
127.0.0.1:6379> DELEX session:1 IFDEQ 0123456789abcdef
(integer) 0
```

## Compatibility

A Redis 8.4 command, with the same conditions as the `IFEQ`, `IFNE`, `IFDEQ`
and `IFDNE` options of [SET](https://docs.hotkv.com/commands/set/index.md).

## See also

[DIGEST](https://docs.hotkv.com/commands/digest/index.md), [SET](https://docs.hotkv.com/commands/set/index.md), [DEL](https://docs.hotkv.com/commands/del/index.md),
[UNLINK](https://docs.hotkv.com/commands/unlink/index.md)