Created
December 25, 2018 06:55
-
-
Save HugoRoca/bd8ea1b88ad9d8628d4e3a9a699be60e to your computer and use it in GitHub Desktop.
REDIS - connection IORedis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const redis = require("ioredis"); | |
const config = require("./config"); | |
module.exports = class RedisConnection { | |
constructor() { | |
this.client = this.connect(); | |
} | |
connect() { | |
let client = new redis({ | |
host: config.redis.host, | |
port: config.redis.port, | |
retryStrategy(times){ | |
let delay = Math.min(times * config.redis.time_to_retry, 200); | |
return delay; | |
}, | |
maxRetriesPerRequest: config.redis.retries | |
}); | |
client.on("connect", () => { | |
console.log("Connectado a redis"); | |
}); | |
client.on("error", err => { | |
console.log(`Redis error: ${err}`); | |
}); | |
return client; | |
} | |
async get(key){ | |
return await this.client.get(key); | |
} | |
async set(key, value){ | |
return await this.client.set(key, value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment