Documentation

databases

Redis

Provision and connect to a managed Redis instance.

Runix provisions a Redis container for caching, session storage, and message queuing. It connects to your services through the internal Docker network.

Provisioning#

runix.yaml
yaml
services:
  - name: cache
    type: redis

  - name: api
    type: web-service
    repo: https://github.com/alice/api
    env:
      REDIS_URL: "${cache.connection_string}"

Connection String#

text
redis://cache:6379

Usage Examples#

Using ioredis

javascript
const Redis = require("ioredis");

const redis = new Redis(process.env.REDIS_URL);

// Set a value with 1-hour expiry
await redis.set("user:123", JSON.stringify({ name: "Alice" }), "EX", 3600);

// Get a value
const user = await redis.get("user:123");
console.log(JSON.parse(user));

Persistence#

By default, Redis stores data only in memory. If the container restarts, all data is lost. You can enable persistence in the dashboard to write data to disk periodically.

For pure caching use cases, leave persistence off. Your app should handle cache misses gracefully. Enable persistence only if you use Redis as a primary data store.