I am a newbie to Jest mocking , I came through this module and wanted to implement it but I am struggling . Hopefully someone can help me here .
I have a helper file which provides me the connection object to ioredis sentinel cluster and I use this helper in another Express route handler file to fetch the values from redis. I am trying to test the route handler file where I need the ioredis mocking .
Any help to get me started is really appreciable .
Redis.js
const Redis = require("ioredis");
const config = require("../config");
const Logger = require("../logger");
const redisLogger = new Logger("redis");
var redis_sentinel_hosts = config.redis_sentinel_hosts;
var redis_sentinel_port = config.redis_sentinel_port;
var redis_sentinel_name = config.redis_sentinel_name;
var redis_sentinel_password = config.redis_sentinel_password;
//Frame the sentinels
var sentinels = [];
var toSplit = redis_sentinel_hosts.split(",");
for (var i = 0; i < toSplit.length; i++) {
sentinels.push({ host: toSplit[i], port: redis_sentinel_port });
}
//Connect to Redis
const redis_client = new Redis({
sentinels: sentinels,
name: redis_sentinel_name,
password: redis_sentinel_password,
sentinelPassword: redis_sentinel_password,
enableOfflineQueue: false, // when redis connection is in error , any command issued wont be put to a queue and error will be thrown
maxRetriesPerRequest: 1,
sentinelRetryStrategy: function (times) {
return 2000; // reconnect after 2 seconds
},
role: "slave", // always connect to slave
});
redis_client.on("connect", function () {
redisLogger.info("Redis client connected to slave");
});
redis_client.on("error", function (err) {
redisLogger.info("Redis client Something went wrong ", err);
});
module.exports = redis_client;
Hey @Abhi-Codes the reason it's not working is because ioredis-mock doesn't support Sentinels yet. This PR needs to land before we can start working on that: #997
I am a newbie to Jest mocking , I came through this module and wanted to implement it but I am struggling . Hopefully someone can help me here . I have a helper file which provides me the connection object to ioredis sentinel cluster and I use this helper in another Express route handler file to fetch the values from redis. I am trying to test the route handler file where I need the ioredis mocking .
Any help to get me started is really appreciable .
Redis.js
Route Handler file .js
Mock_redis.js