daily pastebin goal
36%
SHARE
TWEET

Untitled

a guest Jan 21st, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var redis = require('redis');
  2. class Redis {
  3.     constructor() {
  4.          this.host = process.env.REDIS_HOST || 'localhost'
  5.         this.port = process.env.REDIS_PORT || '6379'
  6.         this.connected = false
  7.         this.client = null
  8.  
  9.     }
  10.    getConnection() {
  11.         if(this.connected) return this.client
  12.         else {
  13.            this.client =  redis.createClient({
  14.                 host: this.host,
  15.                 port: this.port
  16.             })
  17.             return this.client
  18.         }
  19.  
  20.     }
  21. }
  22.  
  23. // This will be a singleton class. After first connection npm will cache this object for whole runtime.
  24. // Every time you will call this getConnection() you will get the same connection back
  25. module.exports = new Redis()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top