Skip to content
Merged
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
24 changes: 18 additions & 6 deletions src/__tests__/ioredis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ import { resumableStreamTests } from "./tests";
import Redis from "ioredis";

if (process.env.REDIS_URL) {
resumableStreamTests(() => {
return {
subscriber: new Redis(process.env.REDIS_URL!),
publisher: new Redis(process.env.REDIS_URL!),
};
}, "ioredis");
describe("default client", () => {
resumableStreamTests(() => {
// Will obtain credentials from the REDIS_URL environment variable automatically
return {
subscriber: undefined,
publisher: undefined,
};
}, "ioredis");
});

describe("custom client", () => {
resumableStreamTests(() => {
return {
subscriber: new Redis(process.env.REDIS_URL!),
publisher: new Redis(process.env.REDIS_URL!),
};
}, "ioredis");
});
} else {
console.error("REDIS_URL is not set, skipping tests");
describe("Redis tests", () => {
Expand Down
10 changes: 8 additions & 2 deletions src/ioredis-adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { Publisher, Subscriber } from "./types";
*/
export function createSubscriberAdapter(client: Redis): Subscriber {
const adapter: Subscriber = {
connect: () => client.connect(),
connect: () => {
// ioredis Redis instances are connected by default. Nothing to do.
return Promise.resolve();
},
subscribe: async function (channel: string, callback: (message: string) => void) {
client.on("message", (innerChannel, message) => {
if (channel === innerChannel) {
Expand All @@ -29,7 +32,10 @@ export function createSubscriberAdapter(client: Redis): Subscriber {
*/
export function createPublisherAdapter(client: Redis): Publisher {
const adapter: Publisher = {
connect: () => client.connect(),
connect: () => {
// ioredis Redis instances are connected by default. Nothing to do.
return Promise.resolve();
},
publish: (channel: string, message: string | Buffer) => client.publish(channel, message),
set: (key: string, value: string | Buffer, options?: { EX?: number }) => {
if (options?.EX) {
Expand Down