happy-server/sources/services/queue/redisProducer.ts
2025-07-26 01:16:22 -07:00

16 lines
443 B
TypeScript

import { redis } from "@/services/redis";
export function createRedisProducer(stream: string) {
return async (messages: string[]) => {
if (messages.length === 0) {
return;
}
// Use pipeline for batch publishing
const pipeline = redis.pipeline();
for (const message of messages) {
pipeline.xadd(stream, '*', 'data', message);
}
await pipeline.exec();
}
}