# Redis Crud

> Use when the user wants to configure saved Redis connection profiles, connect directly or through SSH, inspect keys, get or set string values, delete keys, read or write hash fields, scan keys, ping Redis, or run safe Redis commands with a Bash script, redis-cli, dry-run protections, readonly profiles, local profile storage, SSH tunnel access, or remote-server Redis access through a saved .env REDIS_URL.

- Skill: `finpeakinc/redis-crud` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add finpeakinc/redis-crud`
- Raw SKILL.md: https://api.skillmd.com/api/skills/finpeakinc/redis-crud/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: finpeakinc (https://skillmd.com/u/finpeakinc)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/finpeakinc/redis-crud

---


# Redis CRUD

Safely inspect and change Redis keys through saved local profiles. The skill uses a Bash script and `redis-cli`; it does not depend on Python or `jq`.

## Purpose

Use this skill for:

- saving reusable Redis connection profiles
- direct Redis CLI connections
- SSH tunnel connections to private Redis hosts
- SSH remote execution where `REDIS_URL` exists on a server, such as a remote `.env` file
- `PING`, `GET`, `SET`, `DEL`, `HGET`, `HSET`, `HGETALL`, `SCAN`, and guarded raw Redis commands

Output:

- JSON printed to stdout
- the same JSON saved to `./out/redis-crud-<UTC timestamp>-<pid>.json` by default

## Safety Rules

- Never save Redis credentials in this repository.
- Use `~/.config/redis-crud/profiles/<profile>.conf` for saved profiles.
- Do not print passwords or full Redis URLs; use `list-profiles` for redacted output.
- Prefer read-only commands unless the user clearly asks to mutate data.
- `SET`, `DEL`, `HSET`, and raw write commands dry-run by default.
- Run structured writes with `--execute` only after explicit user confirmation.
- Raw write commands require both `--execute` and `--allow-raw-write`.
- `readonly` profiles must not be used for write commands.
- Prefer structured commands over `raw-command`.
- Prefer repeated `raw-command --arg` values when keys or values contain spaces; `--command` remains available only for simple space-separated commands.

## What This Skill Needs

- `bash`
- local `redis-cli` for `direct` and `ssh-tunnel` profiles
- `ssh` for `ssh-tunnel` and `ssh-remote` profiles
- remote `bash` and `redis-cli` for `ssh-remote` profiles
- one of `nc`, `lsof`, `ss`, or `netstat` for SSH tunnel port checks; the script does not use Bash `/dev/tcp`

## Profile Storage

Profiles are saved under:

```text
~/.config/redis-crud/profiles/
```

The default profile name is saved at:

```text
~/.config/redis-crud/default_profile
```

Each profile is a `0600` shell-style config file. Example:

```bash
MODE=ssh-remote
READONLY=true
SSH_ALIAS=app-prod
REMOTE_CWD=/server/app
ENV_FILE=.env
ENV_KEY=REDIS_URL
```

Do not edit this file by hand unless needed; prefer `configure`.

## Configure Profiles

### Direct Redis

Prefer a full Redis URL when available:

```bash
bash <skill-path>/scripts/redis_crud.sh configure \
  --profile local \
  --mode direct \
  --url "redis://:password@127.0.0.1:6379/0" \
  --default
```

Or use explicit fields:

```bash
bash <skill-path>/scripts/redis_crud.sh configure \
  --profile local \
  --mode direct \
  --redis-host 127.0.0.1 \
  --redis-port 6379 \
  --redis-db 0 \
  --prompt-redis-password \
  --default
```

Add `--test-connection` to verify `PING` before the profile is saved.

### SSH Remote

Use this when the agent should SSH to a server and run the remote `redis-cli` there. This is best when the server has access to a private Redis instance and `REDIS_URL` is already present in a remote `.env` file.

```bash
bash <skill-path>/scripts/redis_crud.sh configure \
  --profile prod \
  --mode ssh-remote \
  --ssh-alias app-prod \
  --remote-cwd /server/app \
  --env-file .env \
  --env-key REDIS_URL \
  --readonly \
  --default
```

The script SSHes to the server, optionally runs `cd <remote_cwd>`, reads `REDIS_URL` from the remote `.env`, and runs `redis-cli` on the remote host. It must not display the full `REDIS_URL`.

Use `--remote-cwd` when the `.env` file exists only inside an application directory after SSH login. `--env-file` may be either relative to `--remote-cwd`, such as `.env`, or an absolute path.

### SSH Tunnel

Use this when the local script should open an SSH tunnel to a private Redis host, then connect locally with `redis-cli`.

```bash
bash <skill-path>/scripts/redis_crud.sh configure \
  --profile staging \
  --mode ssh-tunnel \
  --ssh-host staging.example.com \
  --ssh-user ubuntu \
  --ssh-key ~/.ssh/staging.pem \
  --redis-host 10.0.1.20 \
  --redis-port 6379 \
  --redis-db 0 \
  --prompt-redis-password
```

### List Profiles

```bash
bash <skill-path>/scripts/redis_crud.sh list-profiles
```

The output is redacted.

### Remove Profile

```bash
bash <skill-path>/scripts/redis_crud.sh remove-profile --profile staging
```

## Read Commands

Ping:

```bash
bash <skill-path>/scripts/redis_crud.sh ping --profile prod
```

Get string value:

```bash
bash <skill-path>/scripts/redis_crud.sh get \
  --profile prod \
  --key session:123
```

Read hash field:

```bash
bash <skill-path>/scripts/redis_crud.sh hget \
  --profile prod \
  --key user:123 \
  --field email
```

Read all hash fields:

```bash
bash <skill-path>/scripts/redis_crud.sh hgetall \
  --profile prod \
  --key user:123
```

Scan keys:

```bash
bash <skill-path>/scripts/redis_crud.sh scan \
  --profile prod \
  --pattern "session:*" \
  --count 100
```

Continue a paginated scan with `next_cursor` from the previous response:

```bash
bash <skill-path>/scripts/redis_crud.sh scan \
  --profile prod \
  --pattern "session:*" \
  --count 100 \
  --cursor 384
```

Scan until Redis returns cursor `0`:

```bash
bash <skill-path>/scripts/redis_crud.sh scan \
  --profile prod \
  --pattern "session:*" \
  --count 100 \
  --all
```

## Write Commands

Dry-run `SET` first:

```bash
bash <skill-path>/scripts/redis_crud.sh set \
  --profile staging \
  --key feature:flag \
  --value enabled \
  --ttl 3600
```

Execute only after explicit confirmation:

```bash
bash <skill-path>/scripts/redis_crud.sh set \
  --profile staging \
  --key feature:flag \
  --value enabled \
  --ttl 3600 \
  --execute
```

Dry-run `DEL` first:

```bash
bash <skill-path>/scripts/redis_crud.sh del \
  --profile staging \
  --key session:123
```

Execute only after explicit confirmation:

```bash
bash <skill-path>/scripts/redis_crud.sh del \
  --profile staging \
  --key session:123 \
  --execute
```

Dry-run `HSET` first:

```bash
bash <skill-path>/scripts/redis_crud.sh hset \
  --profile staging \
  --key user:123 \
  --field email \
  --value test@example.com
```

## Raw Commands

Use raw commands for read-only commands when the structured commands are too limited:

```bash
bash <skill-path>/scripts/redis_crud.sh raw-command \
  --profile prod \
  --command "TTL session:123"
```

Use repeated `--arg` values for commands with spaces or complex quoting:

```bash
bash <skill-path>/scripts/redis_crud.sh raw-command \
  --profile prod \
  --arg GET \
  --arg "session key with spaces"
```

Raw write commands require both `--execute` and `--allow-raw-write`:

```bash
bash <skill-path>/scripts/redis_crud.sh raw-command \
  --profile staging \
  --arg EXPIRE \
  --arg session:123 \
  --arg 3600 \
  --execute \
  --allow-raw-write
```

Prefer structured commands when they exist. Prefer `--arg` over `--command` when values contain spaces or complex shell quoting.

## Response Shape

Success responses include:

- `profile`
- `mode`
- `operation`
- operation-specific fields such as `key`, `field`, or `ttl`
- `dry_run` for write previews
- `result`
- `lines`

## Notes

- Use `ssh-remote` for production-style access where the server already knows `REDIS_URL`.
- For `ssh-remote`, set `--remote-cwd` when the `.env` lives inside a project directory on the remote server.
- Use `ssh-tunnel` when Redis is private but commands should run through local `redis-cli`.
- Use `direct` for local or directly reachable Redis.
- Use `configure --test-connection` when the user wants to confirm saved connection details before relying on a profile.
- For `--url`, the script passes the full URL to `redis-cli`, so username, password, database, and TLS-style URL forms supported by `redis-cli` are preserved.
- `ssh-tunnel` port checks use `nc`, `lsof`, `ss`, or `netstat` fallbacks, which keeps the script usable on macOS and Windows shell environments such as Git Bash or WSL.
- This skill is not a Redis migration or backup tool. Do not use it for broad destructive operations unless the user explicitly asks and approves the risk.

## Example Prompts

### Chinese

- "配置一个 Redis profile，名字叫 prod，通过 ssh alias app-prod 到服务器，进入 /server/app 后读取 .env 的 REDIS_URL，只读。"
- "查 prod 里的 session:123。"
- "扫描 prod 里 session:* 的 key。"
- "把 staging 的 feature:flag 设置为 enabled，TTL 3600，先 dry-run。"

### English

- "Configure a readonly Redis profile through SSH using the remote REDIS_URL."
- "Get session:123 using the default Redis profile."
- "Scan keys matching session:*."
- "Preview setting a Redis key with a TTL before executing it."

