unsubscribe failed when stringNumbers is True
Hey luin, here is a bug on unsubscribe mode if set stringNumbers: true, code like this
const Redis = require("ioredis");
// const redis = new Redis({stringNumbers: false});
const redis = new Redis({stringNumbers: true});
redis.subscribe('xxx', (err, count) => {
// unsubscribe
redis.unsubscribe().then(r => {
console.log('---unsub succ', r);
}).catch(e => {
console.log('===unsub fail', e);
})
});
if stringNumbers is false, wverything goes well, '---unsub succ' will be logged, but if it is set to true, nothing will be logged and the promise will not be solved.
ioredis: 5.2.3 Redis: 5.0 Node: 16.14.2
if I pass param xxx in subscribe, the promise will be resolved, but in fact the redis instance is still in sub mode
const Redis = require("ioredis");
// const redis = new Redis({stringNumbers: false});
const redis = new Redis({stringNumbers: true});
redis.subscribe('xxx', (err, count) => {
// unsubscribe
redis.unsubscribe('xxx').then(r => {
console.log('---unsub succ', r);
// this will raise error "Connection in subscriber mode" too
redis.get('name').then(r => {
console.log('get name: ', r);
});
}).catch(e => {
console.log('===unsub fail', e);
})
});
line 157 locates the issue, the reply[2] is string instead of int when stringNumbers, so use == is better
https://github.com/luin/ioredis/blob/eabb70ed835828ad85b602a217992486e05d2218/lib/DataHandler.ts#L150-L160
Ah good catch! Sorry I didn't notice the GitHub notification. Will take a look soon.
:tada: This issue has been resolved in version 5.3.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket: