Sign In
Drivers

Redis

The Redis driver enables deploying scalable Rivet Actors using Redis as the backend for state management and inter-actor communication.

The Redis driver is currently in preview. We do not recommend shipping production applications with the Redis driver yet.

If you want to take Redis to production, contact us so we can help validate your setup is production ready and help resolve issues promptly.

Feature Support

FeatureSupported
Horizontal scalingYes
WebSocketsYes
SSEYes
EdgeNo
SchedulingNot yet

Setup

Install packages

Install the required packages:

Command Line
npm install @rivetkit/redis ioredis@5

Configure the driver

Configure your application using environment variables:

Command Line
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=your-password
REDIS_KEY_PREFIX=myproject

Available Environment Variables:

  • REDIS_HOST - Redis server hostname (default: localhost)
  • REDIS_PORT - Redis server port (default: 6379)
  • REDIS_PASSWORD - Redis password (optional)
  • REDIS_KEY_PREFIX - Key prefix for isolation when running multiple projects (optional)

Then start your server:

server.ts
import { createRedisDriver } from "@rivetkit/redis";
import { registry } from "./registry";

const driver = createRedisDriver();
const { serve, client } = registry.runServer({ driver });

// ...rest of your server...

To prevent data loss, ensure AOF (Append Only File) persistence is enabled on your Redis server. See the Redis Persistence Documentation for setup instructions.

Deploy

Deploy your Redis-powered actors on these hosting providers:

Examples

Advanced

Driver Context

The Redis driver provides access to the underlying Redis connection through the driver context in createVars.

TypeScript
import { actor, ActorInitContext } from "@rivetkit/actor";
import type { DriverContext } from "@rivetkit/redis";

const myActor = actor({
  state: { count: 0 },
  
  // Save the Redis driver context
  createVars: (ctx: ActorInitContext, driver: DriverContext) => ({ redis: driver.redis }),
  
  actions: {
    // Example: Access Redis directly (not recommended in practice)
    getRedisValue: async (c, key: string) => {
      // Use the Redis client from driver context
      return await c.vars.redis.get(key);
    },
  }
});

The Redis driver context type is exported as DriverContext from @rivetkit/redis:

TypeScript
interface DriverContext {
  redis: ioredis.Redis;
  keyPrefix: string;  // Key prefix that all RivetKit data is stored under
}

While you have access to the Redis client, be cautious when directly modifying keys under the keyPrefix, as this may interfere with RivetKit's internal operations and potentially break actor functionality.

Suggest changes to this page