lib/redis-instance.js
/**
 * Initialise a Redis client and attach error handling. The shared `client`
 * instance implements the `get`, `set`, `del` and `incr` methods as Promises,
 * making them easy to use and implement.
 *
 * @param {Object} connectionParams
 */
Initialise a Redis client and attach error handling.

@param {Object} connectionParams
Initialise a Redis client and attach error handling . @param { Object } connectionParams
function initClient(connectionParams = {}) {
	if (client) return
	const options = Object.assign({}, CONNECTION_DEFAULTS, connectionParams)
	const redisClient = redis.createClient(options)
	redisClient.on('error', error => {
		log(error)
		throw error
	})
	client = {
		incr: promisify(redisClient.incr).bind(redisClient),
		get: promisify(redisClient.get).bind(redisClient),
		set: promisify(redisClient.set).bind(redisClient),
		del: promisify(redisClient.del).bind(redisClient),
	}
}
function initClient ( connectionParams = { } ) { if ( client ) return const options = Object . assign ( { } , CONNECTION_DEFAULTS , connectionParams ) const redisClient = redis . createClient ( options ) redisClient . on ( 'error' , error => { log ( error ) throw error } ) client = { incr : promisify ( redisClient . incr ) . bind ( redisClient ) , get : promisify ( redisClient . get ) . bind ( redisClient ) , set : promisify ( redisClient . set ) . bind ( redisClient ) , del : promisify ( redisClient . del ) . bind ( redisClient ) , } }
Initialise a Redis client and attach error handling.
Initialise a Redis client and attach error handling .
// Promisified redis commands need to be rebound to `client` scope // https://stackoverflow.com/questions/44815553/use-node-redis-with-node-8-util-promisify#comment108778017_44926073