Skip to main content

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.

The Redis resource creates a persistent virtual filesystem backed by Redis. It supports full read and write operations.

Config

from mirage import MountMode, Workspace
from mirage.resource.redis import RedisResource

resource = RedisResource(
    url="redis://localhost:6379/0",
    key_prefix="mirage:fs:",
)
ws = Workspace({"/redis": resource}, mode=MountMode.WRITE)
ParameterRequiredDefaultDescription
urlnoredis://localhost:6379/0Redis connection URL
key_prefixnomirage:fs:Key namespace prefix
Keys are stored as:
  • {prefix}file:{path} - file content (raw bytes)
  • {prefix}dir - Redis set of directory paths
  • {prefix}modified:{path} - modification timestamps

Filesystem Layout

/redis/
  <file>
  <directory>/
    <file>
    <subdirectory>/
      <file>
The filesystem is fully user-defined - create any directory structure with mkdir, touch, tee, etc. Example:
/redis/
  config.json
  logs/
    app.log
    error.log
  cache/
    session-abc.json

Cache

Index TTL is 0 - always reads fresh state from Redis.

Example

import asyncio

from mirage import MountMode, Workspace
from mirage.resource.redis import RedisResource

resource = RedisResource(url="redis://localhost:6379/0")


async def main():
    ws = Workspace({"/redis": resource}, mode=MountMode.WRITE)

    # Create directories and files
    await ws.execute("mkdir -p /redis/data/")
    await ws.execute('echo "hello world" | tee /redis/data/hello.txt')

    # Read back
    r = await ws.execute("cat /redis/data/hello.txt")
    print(await r.stdout_str())

    # List files
    r = await ws.execute("ls /redis/data/")
    print(await r.stdout_str())

    # Copy and move
    await ws.execute("cp /redis/data/hello.txt /redis/data/copy.txt")
    await ws.execute("mv /redis/data/copy.txt /redis/data/renamed.txt")

    # Search
    r = await ws.execute('grep "hello" /redis/data/')
    print(await r.stdout_str())

    # Clean up
    await ws.execute("rm -r /redis/data/")


if __name__ == "__main__":
    asyncio.run(main())

Shell Commands

CommandNotes
lsList files and directories
catRead file content
head / tailFirst/last N lines
grep / rgPattern search
wcLine/word/byte counts
findRecursive search with -name, -maxdepth
treeDirectory tree view
mkdirCreate directories
touchCreate empty files
cp / mv / rmCopy, move, delete
teeWrite stdin to file
diff / cmpCompare files
sort / cut / trText processing
tar / zip / gzipCompression
base64 / md5 / sha256sumEncoding and checksums