# Working with Keys — Redis

Source: https://www.geekswithgeeks.com/en/redis/redis-key-commands

> Check, inspect, and safely scan keys.

## EXISTS, DEL, TYPE

The everyday key-management trio: check presence, remove a key, and inspect its data type.

```bash
EXISTS user:1:name
TYPE user:1:name
DEL user:1:name
```

Output:

```
(integer) 1
string
(integer) 1
```

## KEYS is dangerous in production

`KEYS *` scans every key in one blocking call and can freeze a busy server. Use `SCAN` instead — it walks the keyspace in small, non-blocking batches.

```bash
SCAN 0 MATCH "user:*" COUNT 100
```

**Quiz:** Which command should you use to list keys in a production system?

- [ ] KEYS *
- [x] SCAN
- [ ] GETALL

*Answer:* SCAN. `SCAN` iterates incrementally without blocking the server; `KEYS *` blocks until the whole keyspace is scanned.
