Redis DEL Command Explained

In Redis, the DEL command removes one or more keys. If a specified key doesn’t exist, it’s ignored.

Syntax

The syntax goes like this:

DEL key [key ...]

Which means you can delete one or more keys, where each key is the key to delete.

Example

Let’s create a bunch of keys with the MSET command:

MSET firstname "Homer" lastname "Clooney" age "42"

Result:

OK

We can use any number of commands to work with those keys. For example, we can use the MGET command to get their values:

MGET firstname lastname age

Result:

1) "Homer"
2) "Clooney"
3) "42"

And when we no longer need those keys, we can use DEL to delete them:

DEL firstname lastname age

Result:

(integer) 3

Here, we get an integer reply of 3, which means that three keys were deleted.

Now when we try to get the values of those keys, nil is returned:

MGET firstname lastname age

Result:

1) (nil)
2) (nil)
3) (nil)

And if we try to delete the keys again, the operation is ignored:

DEL firstname lastname age

Result:

(integer) 0

No keys were deleted.