ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

Strange behavior of connect with enableOfflineQueue

Open markmcdowell opened this issue 4 years ago • 3 comments

Hello I'm trying to reliably query redis but running into issues with connect.

Version: 4.16.3

Attempt 1

const Redis = require('ioredis')
let redis = new Redis({
  enableOfflineQueue: false,
});
async function getId() {
    try {
        await redis.connect();

        const id = await redis.client('ID')
        console.log(id);
    } catch (error) {
        console.error(error.message)
    }
}
getId()

Output: Redis is already connecting/connected Expected: I'd expect to get the client id logged.

Attempt 2

const Redis = require('ioredis')
let redis = new Redis({
  enableOfflineQueue: false,
});
function getId() {
    redis.connect(async () => {
        try {
            const id = await redis.client('ID')
            console.log(id);
        } catch (error) {
            console.error(error.message)
        }
    });
}
getId()

Output: Stream isn't writeable and enableOfflineQueue options is false Expected: I'd expect to get the client id logged.

Attempt 3

const Redis = require('ioredis')
let redis = new Redis({
  enableOfflineQueue: false,
});
function getId() {
    redis.connect(async () => {
        redis.client('ID', (err, id) => {
            if (err) {
                console.error(err.message)

                return;
            }

            console.log(id);
        });
    });
}
getId()

Output: Stream isn't writeable and enableOfflineQueue options is false Expected: I'd expect to get the client id logged.

Is there anyway I can do this without polling until the stream is writeable?

markmcdowell avatar May 07 '20 17:05 markmcdowell

I'm having the exact same issue. I think it's because the Redis instance it's very slow.

germanattanasio avatar Sep 03 '20 19:09 germanattanasio

I had similar issues but got past them using "lazyConnect"

const redis = new Redis({ enableAutoPipelining: true, 
                          enableOfflineQueue: false,
                          lazyConnect: true});

 await redis.connect();

```

theironcook avatar Sep 16 '21 13:09 theironcook

same issue, but the redis-server not running, it reports node_modules/ioredis/built/redis/index.js:259 const promise = new _Promise((resolve, reject) => { ^ Error: Redis is already connecting/connected at /Users/xxx/work/xxx/node_modules/ioredis/built/redis/index.js:263:20

but when I comment the await redis.connect(), there is no problem.

stardustman avatar Nov 18 '21 06:11 stardustman