Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-facts-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow-worlds/redis": patch
---

fix(redis): added constructor options to connect to Redis with TLS for the main and BullMQ clients
11 changes: 9 additions & 2 deletions packages/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ interface RedisWorldConfig {
// Redis connection string
// Default: process.env.WORKFLOW_REDIS_URI ?? 'redis://localhost:6379'
redisUrl?: string;

// Pre-existing ioredis client (if provided, redisUrl is ignored)

// TLS options for Redis connection
tls?: {
key?: string | Buffer<ArrayBufferLike> | (string | Buffer<ArrayBufferLike> | KeyObject)[];
cert?: string | Buffer<ArrayBufferLike> | (string | Buffer<ArrayBufferLike>)[];
ca?: string | Buffer<ArrayBufferLike> | (string | Buffer<ArrayBufferLike>)[];
};

// Pre-existing ioredis client (if provided, redisUrl and tls are ignored)
client?: Redis;

// Key prefix for all Redis keys
Expand Down
11 changes: 9 additions & 2 deletions packages/redis/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
WorkflowRun,
WorkflowRunWithoutData,
} from '@workflow/world';
import type { ConnectionOptions } from 'tls';
import { Redis } from 'ioredis';
import type { Redis as RedisClient } from 'ioredis';
import { createQueue, type QueueConfig } from './queue.js';
Expand All @@ -34,14 +35,15 @@ import { debug } from './utils.js';
// Module-level client cache to share connections across multiple createWorld() calls
const clientCache = new Map<string, RedisClient>();

function getOrCreateClient(redisUrl: string): RedisClient {
function getOrCreateClient(redisUrl: string, tls?: ConnectionOptions): RedisClient {
const existing = clientCache.get(redisUrl);
if (existing) {
return existing;
}
const client = new Redis(redisUrl, {
maxRetriesPerRequest: null, // Required for BullMQ
enableReadyCheck: false, // Faster connection
tls,
});
clientCache.set(redisUrl, client);

Expand Down Expand Up @@ -70,6 +72,11 @@ export interface RedisWorldConfig extends QueueConfig, StreamerConfig, RedisStor
*/
redisUrl?: string;

/**
* TLS options for the Redis connection.
*/
tls?: ConnectionOptions;

/**
* Pre-existing ioredis client to use.
* If provided, redisUrl is ignored.
Expand All @@ -91,7 +98,7 @@ export function createWorld(config: RedisWorldConfig = {}): World {
?? 'redis://localhost:6379';

// Use provided client or create/get cached one
const client = config.client ?? getOrCreateClient(redisUrl);
const client = config.client ?? getOrCreateClient(redisUrl, config.tls);

debug('Creating world with:', {
redisUrl: redisUrl.replace(/\/\/[^:]*:[^@]*@/, '//***:***@'), // Hide credentials
Expand Down
11 changes: 11 additions & 0 deletions packages/redis/src/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

import { Queue, Worker, Job, type ConnectionOptions, type JobsOptions } from 'bullmq';
import type { ConnectionOptions as TlsConnectionOptions } from 'tls';
import type {
Queue as WorkflowQueue,
MessageId,
Expand All @@ -31,6 +32,11 @@ export interface QueueConfig {
*/
baseUrl?: string;

/**
* TLS options for the Redis connection.
*/
tls?: TlsConnectionOptions;

/**
* Maximum concurrent message processing.
* Default: 20
Expand Down Expand Up @@ -88,6 +94,11 @@ export async function createQueue(options: {
const connection: ConnectionOptions = {
url: redisUrl,
maxRetriesPerRequest: null,
tls: config.tls ? {
key: config.tls.key,
cert: config.tls.cert,
ca: config.tls.ca,
} : undefined,
};

// Create BullMQ queues for workflow and step execution
Expand Down