@@ -3,33 +3,33 @@ import { get } from 'lodash';
3
3
import { convertBulkStringsToObject , convertRedisInfoReplyToObject } from 'src/utils' ;
4
4
5
5
const getTotalFromInfo = async ( client : Redis ) => {
6
- const currentDbIndex = get ( client , [ 'options' , 'db' ] , 0 ) ;
7
- const info = convertRedisInfoReplyToObject (
8
- await client . sendCommand ( new Command ( 'info' , [ 'keyspace' ] , {
9
- replyEncoding : 'utf8' ,
10
- } ) ) as string ,
11
- ) ;
6
+ try {
7
+ const currentDbIndex = get ( client , [ 'options' , 'db' ] , 0 ) ;
8
+ const info = convertRedisInfoReplyToObject (
9
+ await client . sendCommand ( new Command ( 'info' , [ 'keyspace' ] , {
10
+ replyEncoding : 'utf8' ,
11
+ } ) ) as string ,
12
+ ) ;
12
13
13
- const dbInfo = get ( info , 'keyspace' , { } ) ;
14
- if ( ! dbInfo [ `db${ currentDbIndex } ` ] ) {
15
- return 0 ;
16
- }
14
+ const dbInfo = get ( info , 'keyspace' , { } ) ;
15
+ if ( ! dbInfo [ `db${ currentDbIndex } ` ] ) {
16
+ return 0 ;
17
+ }
17
18
18
- const { keys } = convertBulkStringsToObject ( dbInfo [ `db${ currentDbIndex } ` ] , ',' , '=' ) ;
19
- return parseInt ( keys , 10 ) ;
20
- } ;
21
-
22
- const getTotalFromDBSize = async ( client : Redis ) => {
23
- try {
24
- const dbsize = await client . sendCommand ( new Command ( 'dbsize' , [ ] , {
25
- replyEncoding : 'utf8' ,
26
- } ) ) as string ;
27
- return parseInt ( dbsize , 10 ) ;
19
+ const { keys } = convertBulkStringsToObject ( dbInfo [ `db${ currentDbIndex } ` ] , ',' , '=' ) ;
20
+ return parseInt ( keys , 10 ) ;
28
21
} catch ( err ) {
29
22
return - 1 ;
30
23
}
31
24
} ;
32
25
26
+ const getTotalFromDBSize = async ( client : Redis ) => {
27
+ const dbsize = await client . sendCommand ( new Command ( 'dbsize' , [ ] , {
28
+ replyEncoding : 'utf8' ,
29
+ } ) ) as string ;
30
+ return parseInt ( dbsize , 10 ) ;
31
+ } ;
32
+
33
33
export const getTotal = async (
34
34
client : Redis ,
35
35
) : Promise < number > => {
0 commit comments