# Working with Keys — Redis Fundamentals: Caching, Data Structures and Persistence

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

> Check, inspect and delete keys with EXISTS, TYPE and DEL, and scan production keyspaces safely with SCAN.

## 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 *
- [ ] GETALL
- [ ] FLUSHALL
- [x] SCAN

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