@@ -1548,6 +1548,7 @@ export type RedisConnectOptions = {
1548
1548
hostname : string ;
1549
1549
port ?: number | string ;
1550
1550
tls ?: boolean ;
1551
+ db ?: number ;
1551
1552
} ;
1552
1553
1553
1554
/**
@@ -1557,44 +1558,27 @@ export type RedisConnectOptions = {
1557
1558
* const conn = connect({hostname: "127.0.0.1", port: 6379})// -> tcp, 127.0.0.1:6379
1558
1559
* const conn = connect({hostname: "redis.proxy", port: 443, tls: true}) // -> TLS, redis.proxy:443
1559
1560
*/
1560
- export async function connect (
1561
- opts : string | RedisConnectOptions
1562
- ) : Promise < Redis > {
1563
- let conn : Deno . Conn ;
1564
- if ( typeof opts === "string" ) {
1565
- console . warn (
1566
- yellow (
1567
- "deno-redis: connect(addr) is now deprecated and will be removed in v0.5.0 (now v0.4.x)"
1568
- )
1569
- ) ;
1570
- const [ h , p ] = opts . split ( ":" ) ;
1571
- if ( ! p ) {
1572
- throw new Error ( "redis: port must be specified" ) ;
1573
- }
1574
- const dialOptions : DialOptions = { port : parseInt ( p ) } ;
1575
- if ( h ) {
1576
- dialOptions . hostname = h ;
1577
- }
1578
- conn = await Deno . dial ( dialOptions ) ;
1579
- } else {
1580
- const { hostname } = opts ;
1581
- const port = parseInt ( `${ opts . port } ` ) ;
1582
- if ( ! Number . isSafeInteger ( port ) ) {
1583
- throw new Error ( "deno-redis: opts.port is invalid" ) ;
1584
- }
1585
- if ( opts . tls ) {
1586
- conn = await Deno . dialTLS ( {
1587
- hostname,
1588
- port
1589
- } ) ;
1590
- } else {
1591
- conn = await Deno . dial ( {
1592
- hostname,
1593
- port
1594
- } ) ;
1595
- }
1561
+ export async function connect ( {
1562
+ hostname,
1563
+ port,
1564
+ tls,
1565
+ db,
1566
+ } : RedisConnectOptions ) : Promise < Redis > {
1567
+ const dialOpts : DialOptions = {
1568
+ hostname,
1569
+ port : typeof port === "string" ? parseInt ( port ) : port ?? 6379
1570
+ } ;
1571
+ if ( ! Number . isSafeInteger ( dialOpts . port ) ) {
1572
+ throw new Error ( "deno-redis: opts.port is invalid" ) ;
1573
+ }
1574
+ const conn : Deno . Conn = tls
1575
+ ? await Deno . dialTLS ( dialOpts )
1576
+ : await Deno . dial ( dialOpts ) ;
1577
+ const client = await create ( conn , conn , conn ) ;
1578
+ if ( db ) {
1579
+ await client . select ( db ) ;
1596
1580
}
1597
- return create ( conn , conn , conn ) ;
1581
+ return client ;
1598
1582
}
1599
1583
1600
1584
export function create (
0 commit comments