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

# Redis

> Store workspace files in a Redis database.

![](https://mintcdn.com/struktoai/F9Lv_nTaj6By6crk/images/python-logo.svg?fit=max\&auto=format\&n=F9Lv_nTaj6By6crk\&q=85\&s=cf5b268d330f7db46ea5cf6083f309a1)

Node.js

Browser

![](https://mintcdn.com/struktoai/CsxMCKUyfoQQJYHB/images/cloudflare-logo.svg?fit=max\&auto=format\&n=CsxMCKUyfoQQJYHB\&q=85\&s=23668457afa14abb3b0db0f5b9c0541a)

Redis keeps workspace files as keys in a Redis database, under one key prefix.
The files last as long as the database keeps its data.

## Setup

Start a local server (`redis-server` listens on `redis://localhost:6379/0`,
the default) or use a managed one. For Redis Cloud, the endpoint is in the
database's **Configuration** tab and the password of the `default` user under
**Security** (Pro) or **Default user > Configure** (Essentials). Use
`rediss://` when the server needs TLS.

```bash theme={null}
export REDIS_URL=redis://default:<password>@<host>:<port>/0
```

Python needs `pip install "mirage-ai[redis]"`; Node needs the `redis@^5` peer
dependency (`pnpm add @struktoai/mirage-node redis`).

## Connect

> [tab] YAML
>
> ```yaml workspace.yaml theme={null}
> mounts:
>   /redis:
>     vfs: redis
>     mode: write
>     config:
>       url: ${REDIS_URL}
>       key_prefix: "mirage:fs:"
> ```
>
> ```bash theme={null}
> mirage workspace create workspace.yaml --id kv
> mirage shell -w kv -c 'ls /redis'
> ```

> [tab] Python
>
> ```python theme={null}
> import os
>
> from mirage import MountMode, Workspace
> from mirage.vfs.redis import RedisVFS
>
> vfs = RedisVFS(url=os.environ["REDIS_URL"], key_prefix="mirage:fs:")
> ws = Workspace({"/redis": vfs}, mode=MountMode.WRITE)
> result = await ws.shell("ls /redis")
> print(await result.stdout_str())
> await ws.close()
> ```

> [tab] TypeScript
>
> ```typescript theme={null}
> import { MountMode, RedisVFS, Workspace } from '@struktoai/mirage-node'
>
> const ws = new Workspace(
>   {
>     '/redis': new RedisVFS({
>       url: process.env.REDIS_URL!,
>       keyPrefix: 'mirage:fs:',
>     }),
>   },
>   { mode: MountMode.WRITE },
> )
> const result = await ws.shell('ls /redis')
> console.log(result.stdoutText)
> await ws.close()
> ```

## Layout

```text theme={null}
/redis/
  config.json
  cache/
    session-abc.json
  logs/
    app.log
```

* The tree is whatever commands write. Each file is a `<prefix>file:<path>`
  key; a different `key_prefix` keeps a workspace apart from other data.
* Runs in Python, Node and Cloudflare Workers over the Redis protocol.
* A browser has no socket, so it mounts Redis through the Upstash REST API;
  see [browser Redis setup](https://docs.mirage.strukto.ai/typescript/vfs/redis.md#browser).

## Sample runs

```bash theme={null}
$ tree /redis
/redis
|-- cache
|   `-- session-abc.json
|-- config.json
`-- logs
    `-- app.log

3 directories, 3 files
```

```bash theme={null}
$ grep -rn retry /redis/logs
/redis/logs/app.log:2:retry 1
```

```bash theme={null}
$ cat /redis/config.json
{"theme": "dark"}
```

Every command that writes works on a `write` mount. Add `capacity: 100MB`
under `config` to cap the bytes the files hold; see
[capacity](https://docs.mirage.strukto.ai/home/setup/vfs.md#mount-capacity).

## SDK guides

> [card] [Python](https://docs.mirage.strukto.ai/python/vfs/redis.md)
>
> Every config field, the VFS.md and write support.

> [card] [TypeScript](https://docs.mirage.strukto.ai/typescript/vfs/redis.md)
>
> Every config field, the VFS.md and write support.


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