Nodevisor Docs
Services

Redis

Redis cache and data store with persistence and memory management.

Overview

The Redis service provides a production-ready Redis instance with optional persistence, memory limits, eviction policies, and built-in health checks. It extends PortDockerService and exposes a single port.

Quick Start

import { DockerCluster, Redis } from '@nodevisor/docker';

const cluster = new DockerCluster({ name: 'production', ... });

cluster.addDependency(new Redis({
  password: process.env.REDIS_PASSWORD!,
  maxmemory: '256mb',
  maxmemoryPolicy: 'allkeys-lru',
}));

Configuration

RedisConfig

OptionTypeDefaultDescription
namestring'redis'Service name
versionstring'8.0.2'Redis version
imagestring'redis:{version}'Docker image
portnumber6379Redis port
passwordstringundefinedRedis password
appendonlybooleanundefinedEnable AOF persistence
maxmemorystring | numberundefinedMemory limit (e.g., '256mb' or 256 for MB)
maxmemoryPolicyMaxmemoryPolicyundefinedEviction policy when memory limit is reached
volumeDockerVolumeundefinedCustom volume configuration
healthcheckDockerHealthcheckConfigBuilt-in (see below)Custom health check config

MaxmemoryPolicy

PolicyDescription
'noeviction'Return errors when memory limit is reached
'allkeys-lru'Evict least recently used keys (recommended for caches)
'allkeys-random'Evict random keys
'volatile-lru'Evict least recently used keys with TTL set
'volatile-random'Evict random keys with TTL set
'volatile-ttl'Evict keys with shortest TTL

Health Check

PropertyValue
Commandredis-cli ping | grep PONG
Interval10s
Timeout2s
Retries3
Start period5s

Volumes

VolumeTargetTypeDescription
data/datavolumePersistent Redis data (RDB snapshots and AOF files)

Environment Variables

VariableSourceDescription
REDIS_PASSWORDpasswordRedis authentication password

Command Arguments

Redis server command arguments are configured automatically based on your options:

ArgumentSourceExample
--appendonlyappendonly: trueredis-server --appendonly yes
--maxmemorymaxmemory: '256mb'redis-server --maxmemory 256mb
--maxmemory-policymaxmemoryPolicy: 'allkeys-lru'redis-server --maxmemory-policy allkeys-lru

When maxmemory is a number, it's treated as megabytes (e.g., 256 becomes '256mb').

Usage with DockerCluster

import {
  DockerCluster, DockerNode, ClusterUser,
  Traefik, Postgres, Redis, NodeWeb, DockerRegistry,
} from '@nodevisor/docker';

const cluster = new DockerCluster({
  name: 'production',
  nodes: [new DockerNode({ host: '10.0.0.1' })],
  users: [new ClusterUser({ username: 'root', privateKeyPath: '~/.ssh/id_ed25519' })],
  registry: new DockerRegistry({
    server: 'ghcr.io',
    username: 'myorg',
    password: process.env.REGISTRY_TOKEN!,
  }),
});

cluster.addDependency(new Traefik({
  ssl: { email: 'ops@example.com', redirect: true },
}));

cluster.addDependency(new Postgres({
  database: 'myapp',
  password: process.env.DB_PASSWORD!,
}));

cluster.addDependency(new Redis({
  password: process.env.REDIS_PASSWORD!,
  appendonly: true,
  maxmemory: '256mb',
  maxmemoryPolicy: 'allkeys-lru',
}));

cluster.addDependency(new NodeWeb({
  name: 'api',
  appDir: './apps/api',
  domains: ['api.example.com'],
  environment: {
    REDIS_URL: `redis://:${process.env.REDIS_PASSWORD}@redis:6379`,
  },
}));

await cluster.deploy();

The connection string uses the service name redis as the hostname — Docker's internal DNS resolves it automatically.

On this page