ioredis
ioredis copied to clipboard
Strange behavior of connect with enableOfflineQueue
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?
I'm having the exact same issue. I think it's because the Redis instance it's very slow.
I had similar issues but got past them using "lazyConnect"
const redis = new Redis({ enableAutoPipelining: true,
enableOfflineQueue: false,
lazyConnect: true});
await redis.connect();
```
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.