diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8d9c9bc --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "editor.formatOnSave": false +} \ No newline at end of file diff --git a/index.js b/index.js index e544b57..dfb0aa1 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const IoRedis = require('ioredis'); +const redisTimeout = require('ioredis-timeout'); function retryStrategy(times) { @@ -32,10 +33,12 @@ class Redis { * @param {string} name - unique name to this service * @param {EventEmitter} emitter * @param {Object} config - configuration object of service + * @param {number} commandTimeout - config for command timeout in ms */ - constructor(name, emitter, config) { + constructor(name, emitter, config, commandTimeout) { this.name = name; this.emitter = emitter; + this.commandTimeout = commandTimeout; this.config = Object.assign({ host: 'localhost', port: 6379, @@ -170,6 +173,7 @@ class Redis { } this.log(`Connecting in ${infoObj.mode} mode`, infoObj); + redisTimeout(client, this.commandTimeout); // common events client.on('connect', () => { diff --git a/package.json b/package.json index 5ce94ac..0bb978e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ }, "homepage": "https://github.com/akshendra/redis-wrapper#readme", "dependencies": { - "ioredis": "^3.2.2" + "ioredis": "^3.2.2", + "ioredis-timeout": "^1.5.0" }, "devDependencies": { "eslint": "^5.9.0",