@@ -94,8 +94,8 @@ function RedisClient (options) {
94
94
this . monitoring = false ;
95
95
this . closing = false ;
96
96
this . server_info = { } ;
97
- this . auth_pass = options . auth_pass ;
98
- this . selected_db = null ; // Save the selected db here, used when reconnecting
97
+ this . auth_pass = options . auth_pass || options . password ;
98
+ this . selected_db = options . db ; // Save the selected db here, used when reconnecting
99
99
this . old_state = null ;
100
100
this . send_anyway = false ;
101
101
this . pipeline = 0 ;
@@ -1265,12 +1265,23 @@ var createClient = function (port_arg, host_arg, options) {
1265
1265
} else if ( typeof port_arg === 'string' || port_arg && port_arg . url ) {
1266
1266
options = clone ( port_arg . url ? port_arg : host_arg || options ) ;
1267
1267
var parsed = URL . parse ( port_arg . url || port_arg , true , true ) ;
1268
+ // [redis:]//[user][:password@][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]
1268
1269
if ( parsed . hostname ) {
1269
1270
if ( parsed . auth ) {
1270
- options . auth_pass = parsed . auth . split ( ':' ) [ 1 ] ;
1271
+ options . password = parsed . auth . split ( ':' ) [ 1 ] ;
1271
1272
}
1272
- if ( parsed . protocol !== 'redis:' ) {
1273
- throw new Error ( 'Connection string must use the "redis:" protocol' ) ;
1273
+ if ( ! / ^ ( [ a - z ] + : ) ? \/ \/ / i. test ( parsed . href ) ) {
1274
+ throw new Error ( 'Connection string must use the "redis:" protocol or begin with slashes //' ) ;
1275
+ }
1276
+ if ( parsed . pathname && parsed . pathname !== '/' ) {
1277
+ options . db = parsed . pathname . substr ( 1 ) ;
1278
+ }
1279
+ if ( parsed . search !== '' ) {
1280
+ var elem ;
1281
+ for ( elem in parsed . query ) { // jshint ignore: line
1282
+ // If options are passed twice, only the parsed options will be used
1283
+ options [ elem ] = parsed . query [ elem ] ;
1284
+ }
1274
1285
}
1275
1286
options . host = parsed . hostname ;
1276
1287
options . port = parsed . port ;
0 commit comments