# Redis and MongoDB

Source: https://laraport.app/docs/redis-mongodb/

> Find Redis keys by pattern with their type, TTL and size, read values, delete a key after a confirmation, and inspect Redis and MongoDB in containers.

## Redis

The **Redis** entry appears for a container with `redis-cli`, and **Redis (app)** for the Redis the Laravel app uses. The password comes from `REDIS_PASSWORD` or `REDIS_URL` and is passed through `REDISCLI_AUTH`, never with `-a`.

The commands are read-only:

- **Info and stats**: `INFO` sections, `DBSIZE`, `CLIENT LIST`;
- **Keys**: a sample of keys and their count, using `SCAN`, never `KEYS *`; the key distribution; `SLOWLOG GET 10`;
- **Configuration**: `maxmemory`, `maxmemory-policy`, `save`, `appendonly`;
- **Maintenance**: `PING`, `LASTSAVE`, `LATENCY DOCTOR`;
- **Backup**: an RDB snapshot (`redis-cli --rdb`) saved to your downloads folder.

## Redis keys

**Redis keys** (for the container's Redis) and **Redis keys (app)** (for the Redis the app uses) on the Data tab find keys by pattern and show their values.

The screen starts with the pattern `*`. `/` edits it: `laravel_cache:*`, `*session*`. `enter` scans with the new pattern.

Each key is listed with its type, its expiry and its size: the bytes of a string, or the number of items of a hash, list, set, sorted set or stream.

| Key | Action |
|---|---|
| `/` | Edit the pattern |
| `enter` | The key's value |
| `D` | Delete the key |
| `r` | Scan again |

The value is laid out by type: a string, a hash's fields, a list's items, a set's members, a sorted set's scores, a stream's entries. Only the first 200 items or 64 KB are read.

`D` deletes the key with `UNLINK` after a confirmation, and the keys are scanned again. A [read-only server](https://laraport.app/docs/read-only/) refuses it.

The scan is bounded so it never blocks a busy server: at most 100 `SCAN` steps and 500 keys. When it stops early, the title says so: narrow the pattern to see the rest. Each read is one Lua script, so keys with spaces or quotes are safe, and the password goes over stdin as for the other commands.

## MongoDB

The **MongoDB** entry appears for a container with `mongosh` or the older `mongo` shell. Root credentials come from `MONGO_INITDB_ROOT_USERNAME` and `MONGO_INITDB_ROOT_PASSWORD`, or from `MONGO_URL` / `MONGODB_URI`. With `mongosh` they are read inside the script, so they never appear on a command line.

- **Info and stats**: version, server status, databases, `db.stats()`, operations in progress;
- **Collections**: document counts and sizes;
- **Indexes** of every collection;
- **Maintenance**: `ping`, replica set status, profiling;
- **Backup**: `mongodump --archive --gzip`, restored with `mongorestore --archive=… --gzip`.
