socketio / socket.io-admin-ui

Admin UI for Socket.IO

Home Page:https://admin.socket.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@socket.io/admin-ui is not compatible with @socket.io/redis-adapter

owaistariq8 opened this issue · comments

Node version: 16.15.1
npm:8.11.0
@socket.io/admin-ui :0.4.0
@socket.io/redis-adapter:7.2.0

Following code will produce error
`
const http = require('http');
const express = require('express');
const socketio = require('socket.io');

const { createClient } = require("redis");
const { createAdapter } = require("@socket.io/redis-adapter");
const { instrument } = require("@socket.io/admin-ui");
const app = express();
const server = http.createServer(app);
const io = socketio(server, {transports: ['websocket'],});

const pubClient = createClient({ url: redis://${REDIS_HOST}:${REDIS_PORT} });
const subClient = pubClient.duplicate();

io.adapter(createAdapter(pubClient, subClient));
`

Error given below

var/www/html/ludo-app-server/node_modules/@redis/client/dist/lib/client/index.js:407 return Promise.reject(new errors_1.ClientClosedError()); ^ ClientClosedError: The client is closed at Commander._RedisClient_sendCommand (/var/www/html/ludo-app-server/node_modules/@redis/client/dist/lib/client/index.js:407:31) at Commander.commandsExecutor (/var/www/html/ludo-app-server/node_modules/@redis/client/dist/lib/client/index.js:170:154) at Commander.BaseClass.<computed> [as publish] (/var/www/html/ludo-app-server/node_modules/@redis/client/dist/lib/commander.js:8:29) at RedisAdapter.broadcast (/var/www/html/ludo-app-server/node_modules/@socket.io/redis-adapter/dist/index.js:463:28) at BroadcastOperator.emit (/var/www/html/ludo-app-server/node_modules/socket.io/dist/broadcast-operator.js:125:26) at Namespace.emit (/var/www/html/ludo-app-server/node_modules/socket.io/dist/namespace.js:170:73) at emitStats (/var/www/html/ludo-app-server/node_modules/@socket.io/admin-ui/dist/index.js:92:24) at initStatsEmitter (/var/www/html/ludo-app-server/node_modules/@socket.io/admin-ui/dist/index.js:102:5) at instrument (/var/www/html/ludo-app-server/node_modules/@socket.io/admin-ui/dist/index.js:432:5)

package.json dependencies
"dependencies": { "@elastic/ecs-winston-format": "^1.3.1", "@socket.io/admin-ui": "^0.4.0", "@socket.io/redis-adapter": "^7.2.0", "aws-sdk": "^2.968.0", "axios": "^0.27.2", "bufferutil": "^4.0.6", "bull": "^4.8.4", "debug": "^4.2.0", "dotenv": "^16.0.1", "eiows": "^4.1.2", "express": "^4.17.1", "express-rate-limit": "^6.4.0", "fs": "^0.0.1-security", "got": "^12.1.0", "ioredis": "^5.0.4", "ip": "^1.1.5", "joi": "^17.3.0", "jsonwebtoken": "^8.5.1", "mongoose": "^6.4.1", "node-cron": "^3.0.1", "package-json": "^8.1.0", "rate-limiter-flexible": "^2.1.13", "redis": "^4.1.0", "shelljs": "^0.8.4", "socket.io": "^4.0.0", "socket.io-client": "^4.4.1", "template-file": "^6.0.1", "truncate-logs": "^1.0.4", "utf-8-validate": "^5.0.8", "uuid": "^8.3.2", "winston": "^3.6.0" }, "devDependencies": { "nodemon": "^2.0.18" }

Hi!

I think you need to call redisClient.connect():

const pubClient = createClient({ url: redis://${REDIS_HOST}:${REDIS_PORT} });
const subClient = pubClient.duplicate();

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

io.adapter(createAdapter(pubClient, subClient));

Reference: https://github.com/redis/node-redis#basic-example

Thanks its working.