-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Error: Cannot send commands in PubSub mode when using redis server with password #2332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ngocson952006 Hi, can you please provide a code example that reproduces the issue? because this code didn't: import { createClient } from '@redis/client';
const client = createClient({
username: 'default',
password: '123'
});
client.on('error', err => console.error(err));
await client.connect();
await client.subscribe('test', (message) => {
console.log(message);
});
console.log('Restart redis server now'); edit: maybe it was fixed in 4.5.0? 🤔 |
Thanks, @leibale for your response. Honestly, I can not share the code because it's from my work project. But I can explain follow I that I encountered the error. My project uses Node-Redis to read, and write Redis data and also uses Pub/Sub for notification handling.
We use the URL to connect to Redis-Server and save this to the environment variable. The pattern of URL is followed by Then, from another business logic class, I want to use Pub/Sub with the same URL connection. I created a duplicate connection.
At this point, I have a problem. The PubSub code works fine for the case of Redis without a password(example URL: redis://localhost:16379/0). In case Redis with password (example URL: redis://:password_123@localhost:6379/0), the code raises the error |
@ngocson952006 I had the same issue and i realized that I was not awaiting on the redis client connection before calling the subscribe() function. Make sure to await the connection first and I believe the issue will be resolved. |
Thanks @bmiller59, you saved my day. I need to wait for all clients(including the duplicated client) to be connected first. |
Using the Pub/Sub feature described at https://redis.js.org/#node-redis-usage-pubsub works fine for me when using a Redis server without a password set.
But when changing connect to a Redis server using a password for authentication, I got the error
Cannot send commands in PubSub mode
(Despite that the connection was successful). Details belowI'm not sure if this is duplicated with #2080 but the version of the lib I'm using is v4.4.0.
Environment:
The text was updated successfully, but these errors were encountered: