@ -1,37 +1,34 @@
'use strict' ;
const nconf = require ( 'nconf' ) ;
const r edis = require ( ' redis') ;
const R edis = require ( ' io redis') ;
const winston = require ( 'winston' ) ;
const _ = require ( 'lodash' ) ;
const connection = module . exports ;
connection . getConnectionOptions = function ( redis ) {
redis = redis || nconf . get ( 'redis' ) ;
const connOptions = { } ;
if ( redis . password ) {
connOptions . auth _pass = redis . password ;
}
if ( redis . hasOwnProperty ( 'database' ) ) {
connOptions . db = redis . database ;
}
return _ . merge ( connOptions , redis . options || { } ) ;
} ;
connection . connect = async function ( options ) {
return new Promise ( ( resolve , reject ) => {
options = options || nconf . get ( 'redis' ) ;
const redis _socket _or _host = options . host ;
const connOptions = connection . getConnectionOptions ( options ) ;
let cxn ;
if ( redis _socket _or _host && String ( redis _socket _or _host ) . indexOf ( '/' ) >= 0 ) {
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
cxn = redis . createClient ( options . host , connOptions ) ;
// If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock
cxn = new Redis ( {
... options . options ,
path : redis _socket _or _host ,
password : options . password ,
db : options . database ,
} ) ;
} else {
/* Else, connect over tcp/ip */
cxn = redis . createClient ( options . port , options . host , connOptions ) ;
// Else, connect over tcp/ip
cxn = new Redis ( {
... options . options ,
host : redis _socket _or _host ,
port : options . port ,
password : options . password ,
db : options . database ,
} ) ;
}
const dbIdx = parseInt ( options . database , 10 ) ;
@ -44,6 +41,8 @@ connection.connect = async function (options) {
reject ( err ) ;
} ) ;
cxn . on ( 'ready' , ( ) => {
// back-compat with node_redis
cxn . batch = cxn . pipeline ;
resolve ( cxn ) ;
} ) ;