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

Commit

Permalink
use redis instead of ioredis
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeppner-dataport committed Apr 3, 2024
1 parent 4fc7357 commit 829df12
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 75 deletions.
145 changes: 77 additions & 68 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",
"ioredis": "^5.3.2",
"redis": "^4.6.13",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"socket.io": "^4.7.4",
Expand Down
12 changes: 6 additions & 6 deletions src/socket/socket/redis-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { IoAdapter } from '@nestjs/platform-socket.io';
import { Redis } from 'ioredis';
import { createClient } from 'redis';
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 = new Redis(
process.env.REDIS_URI || `redis://localhost:6379`,
);
const pubClient = createClient({
url: process.env.REDIS_URI || 'redis://localhost:6379',
});
const subClient = pubClient.duplicate();

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

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

0 comments on commit 829df12

Please sign in to comment.