Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
use ioredis again
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Apr 3, 2024
1 parent 829df12 commit ebebb2e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 84 deletions.
145 changes: 68 additions & 77 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@nestjs/platform-socket.io": "^10.3.3",
"@nestjs/websockets": "^10.3.3",
"@socket.io/redis-adapter": "^8.3.0",
"redis": "^4.6.13",
"ioredis": "^5.3.2",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"socket.io": "^4.7.4",
Expand Down
13 changes: 7 additions & 6 deletions src/socket/socket/redis-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { createClient } from 'redis';
import { IoAdapter } from '@nestjs/platform-socket.io';
import { Redis } from 'ioredis';
import { ServerOptions } from 'socket.io';
import { createAdapter } from '@socket.io/redis-adapter';
import { IoAdapter } from '@nestjs/platform-socket.io';

export class RedisIoAdapter extends IoAdapter {
private adapterConstructor: ReturnType<typeof createAdapter>;

async connectToRedis(): Promise<void> {
const pubClient = createClient({
url: process.env.REDIS_URI || 'redis://localhost:6379',
});
const pubClient = new Redis(
process.env.REDIS_URI || `redis://localhost:6379`,
);
const subClient = pubClient.duplicate();

await Promise.all([pubClient.connect(), subClient.connect()]);
await pubClient.connect();
await subClient.connect();

this.adapterConstructor = createAdapter(pubClient, subClient);
}
Expand Down

0 comments on commit ebebb2e

Please sign in to comment.