Dragonfly Cloud is now available in the AWS Marketplace - learn more

Error: redis.cluster is not a constructor

What's Causing This Error

The error message 'redis.cluster is not a constructor' typically indicates that you're trying to use the Redis.Cluster feature in a way it wasn't intended, or in a context where it isn't defined. In JavaScript, this kind of error generally occurs when you try to instantiate a class that doesn't exist or hasn't been properly imported.

One common cause could be using an outdated or incompatible version of the Redis Node.js client library. Not all versions support the Cluster class, hence the error might occur if you're trying to create a new instance of Redis.Cluster with a version that does not have this feature.

Another possible reason might be a problem with how your code is structured or how the Redis library is being imported. If the library isn't correctly included in your script or the cluster object isn't properly instantiated, you'll also encounter this error.

Solution - Here's How To Resolve It

Here are some ways to fix the 'redis.cluster is not a constructor' error:

  1. Update your Redis client library: Make sure you're using a version of the Redis library that supports clustering. You can check the documentation for your specific Redis client to see what versions offer this feature and how to upgrade.

  2. Correctly import the Redis library: Ensure that the Redis library is properly imported into your JavaScript file. It should look something like const Redis = require('ioredis'); if you're using ioredis.

  3. Properly instantiate the cluster object: When creating a new instance of Redis.Cluster, ensure that you're following the correct syntax. An example would be:

let cluster = new Redis.Cluster([{host: '127.0.0.1', port: 6379}]);
  1. Check your code structure: Finally, make sure there are no issues with how your code is written or structured that could be causing this error. Check whether your instantiation of Redis.Cluster is being done in the correct scope and isn't getting overshadowed or garbage collected.

By following these steps, you should be able to resolve the 'redis.cluster is not a constructor' error.

Was this content helpful?

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost