Ioredis: Cannot read property 'dropBufferSupport' of undefined

Created on 22 Apr 2020  路  5Comments  路  Source: luin/ioredis

Hi,
unfortunately I come across this error using ioredis in typescript:

TypeError: Cannot read property 'dropBufferSupport' of undefined at RedisManager.set (/Users/x/Documents/Github/x/backend/node_modules/ioredis/built/commander.js:110:26)

I use a standard setup and a simple test
this.client = new Redis({ host: Config.redis.host, port: Config.redis.port, dropBufferSupport: false });
.....
this.client.on('ready', async () => { Logger.info("Redis connected and healthy."); try { await this.set('Test', 'X'); console.log(await this.get('Test')); this.health = true; } catch(err){ console.error(err); } });

Node-Version: 13.10.1
Redis-Version: 5.0.3
ioredis: 4.16.3

Help would be highly appreciated :-)

Most helpful comment

@JannikSt, From your example I would assume it's a problem with the way you reference ioredis and use functions - when you use an arrow function, this context is retained from where you defined the this.client.on call. Try using a plain function over an arrow function, those can be bound and called with context supplied to them. Otherwise, a more elaborate example would help.
I encountered this problem when trying to build a module interface in a file and just export the set and get functions from the module:

// wrong.js
const cache = new Redis(config);
module.exports = {
  set: cache.set,
  get: cache.get,
};

// working.js
const cache = new Redis(config);
module.exports = {
  set: async (key, value, ttl=30) => cache.set(key, value, 'EX', ttl),
  get: async (key) => cache.get(key),
};

// alternative.js
const cache = new Redis(config);
module.exports = {
  set: cache.set.bind(cache),
  get: cache.get.bind(cache),
};

All 5 comments

It seems to be a compatibility issue. Does simply removing node_modules folder and running npm i again solve the issue? Also, can you upgrade ioredis as the version is dated.

Hi,
thank you for your reply!
I had a typo in my version and fixed the description.
Unfortunately, deleting the node_modules folder and reinstalling it did not help.

I also manually tried to enable / disable the dropBufferSupport but the same error occurred.
Do you have other ideas?

I am also facing this issue. @JannikSt Were you able to figure it out?

@JannikSt, From your example I would assume it's a problem with the way you reference ioredis and use functions - when you use an arrow function, this context is retained from where you defined the this.client.on call. Try using a plain function over an arrow function, those can be bound and called with context supplied to them. Otherwise, a more elaborate example would help.
I encountered this problem when trying to build a module interface in a file and just export the set and get functions from the module:

// wrong.js
const cache = new Redis(config);
module.exports = {
  set: cache.set,
  get: cache.get,
};

// working.js
const cache = new Redis(config);
module.exports = {
  set: async (key, value, ttl=30) => cache.set(key, value, 'EX', ttl),
  get: async (key) => cache.get(key),
};

// alternative.js
const cache = new Redis(config);
module.exports = {
  set: cache.set.bind(cache),
  get: cache.get.bind(cache),
};

@alesbolka Thank you! This got me too...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iamjochem picture iamjochem  路  5Comments

pensierinmusica picture pensierinmusica  路  5Comments

pavanratnakar picture pavanratnakar  路  4Comments

snig-b picture snig-b  路  5Comments

luckyscript picture luckyscript  路  5Comments