ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

unsubscribe failed when stringNumbers is True

Open qishibo opened this issue 3 years ago • 3 comments

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.

qishibo avatar Aug 30 '22 13:08 qishibo

ioredis: 5.2.3 Redis: 5.0 Node: 16.14.2

qishibo avatar Aug 30 '22 13:08 qishibo

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);
  })
});

qishibo avatar Aug 30 '22 14:08 qishibo

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

qishibo avatar Aug 31 '22 02:08 qishibo

Ah good catch! Sorry I didn't notice the GitHub notification. Will take a look soon.

luin avatar Jan 25 '23 13:01 luin

:tada: This issue has been resolved in version 5.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Jan 25 '23 16:01 github-actions[bot]