# RANDOMKEY

> Return a random key from the current database.

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

```
RANDOMKEY
```

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

`RANDOMKEY` returns the name of a key picked at random from the selected
database. Use it for sampling or spot checks; it is not meant for iterating
over the keyspace (use [SCAN](https://docs.hotkv.com/commands/scan/index.md) for that).

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The database has keys | Bulk string: a key name | Bulk string |
| The database is empty | Nil bulk string | Null |

## Examples

```
127.0.0.1:6379> MSET a 1 b 2 c 3
OK
127.0.0.1:6379> RANDOMKEY
"b"
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[SCAN](https://docs.hotkv.com/commands/scan/index.md), [KEYS](https://docs.hotkv.com/commands/keys/index.md)