Skip to content

Instantly share code, notes, and snippets.

@HugoRoca
Created December 25, 2018 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HugoRoca/bd8ea1b88ad9d8628d4e3a9a699be60e to your computer and use it in GitHub Desktop.
Save HugoRoca/bd8ea1b88ad9d8628d4e3a9a699be60e to your computer and use it in GitHub Desktop.
REDIS - connection IORedis
"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