> ## Documentation Index
> Fetch the complete documentation index at: https://docs.microsandbox.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Redis

> Run an authenticated Redis service with persistent data

Local-only (This guide publishes Redis to a port on the computer running the CLI, which is not available on microsandbox cloud.)

This guide starts Redis 7 with password authentication, a sized root disk, and a localhost-only forwarded port.

## Run Redis

**1. Start Redis**

Set a temporary password in the host shell:

```sh macOS & Linux theme={null}
export REDIS_PASSWORD="$(openssl rand -hex 24)"
```

```powershell Windows theme={null}
$bytes = New-Object byte[] 24
$rng = [Security.Cryptography.RandomNumberGenerator]::Create()
$rng.GetBytes($bytes)
$rng.Dispose()
$env:REDIS_PASSWORD = -join ($bytes | ForEach-Object { $_.ToString('x2') })
```

Start Redis:

```sh macOS & Linux theme={null}
msb run -d --name redis-demo --replace \
  --cpus 1 --memory 512M --root-disk 2G \
  -p 127.0.0.1:56379:6379 \
  redis:7-alpine -- redis-server \
    --bind 0.0.0.0 \
    --protected-mode yes \
    --appendonly yes \
    --requirepass "$REDIS_PASSWORD"
```

```powershell Windows theme={null}
msb run -d --name redis-demo --replace `
  --cpus 1 --memory 512M --root-disk 2G `
  -p 127.0.0.1:56379:6379 `
  redis:7-alpine -- redis-server `
    --bind 0.0.0.0 `
    --protected-mode yes `
    --appendonly yes `
    --requirepass $env:REDIS_PASSWORD
```

**2. Verify reads and writes**

Write a test value:

```sh macOS & Linux theme={null}
msb exec redis-demo -- \
  redis-cli -a "$REDIS_PASSWORD" --no-auth-warning SET example ready
```

```powershell Windows theme={null}
msb exec redis-demo -- `
  redis-cli -a $env:REDIS_PASSWORD --no-auth-warning SET example ready
```

Read it back:

```sh macOS & Linux theme={null}
msb exec redis-demo -- \
  redis-cli -a "$REDIS_PASSWORD" --no-auth-warning GET example
```

```powershell Windows theme={null}
msb exec redis-demo -- `
  redis-cli -a $env:REDIS_PASSWORD --no-auth-warning GET example
```

Finally, check that the server responds:

```sh macOS & Linux theme={null}
msb exec redis-demo -- \
  redis-cli -a "$REDIS_PASSWORD" --no-auth-warning PING
```

```powershell Windows theme={null}
msb exec redis-demo -- `
  redis-cli -a $env:REDIS_PASSWORD --no-auth-warning PING
```

The three commands should return `OK`, `ready`, and `PONG`. Host applications connect to `127.0.0.1:56379`.

> [!WARNING]
>
> `--requirepass` places the demo password in the guest process arguments. For production, use an ACL file delivered through the [secrets workflow](https://docs.microsandbox.dev/sandboxes/secrets.md) and do not expose the forwarded port beyond loopback.

**3. Clean up**

Remove the sandbox and its append-only database:

```sh Shell theme={null}
msb rm -f redis-demo
```

Clear the password from the host shell:

```sh macOS & Linux theme={null}
unset REDIS_PASSWORD
```

```powershell Windows theme={null}
Remove-Item Env:REDIS_PASSWORD
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.