You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-2Lines changed: 9 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,8 @@ npm install redis-parser
19
19
## Usage
20
20
21
21
```js
22
+
var Parser =require('redis-parser');
23
+
22
24
newParser(options);
23
25
```
24
26
@@ -28,7 +30,8 @@ new Parser(options);
28
30
*`returnError`: *function*; mandatory
29
31
*`returnFatalError`: *function*; optional, defaults to the returnError function
30
32
*`returnBuffers`: *boolean*; optional, defaults to false
31
-
*`name`: *javascript|hiredis*; optional, defaults to hiredis and falls back to the js parser if not available
33
+
*`name`: *javascript|hiredis*; optional, defaults to hiredis and falls back to the js parser if not available or if the stringNumbers option is choosen
34
+
*`stringNumbers`: *boolean*; optional, defaults to false. This is only available for the javascript parser at the moment!
32
35
33
36
### Example
34
37
@@ -64,7 +67,9 @@ Library.prototype.streamHandler = function () {
64
67
```
65
68
You do not have to use the returnFatalError function. Fatal errors will be returned in the normal error function in that case.
66
69
67
-
And if you want to return buffers instead of strings, you can do this by adding the returnBuffers option.
70
+
And if you want to return buffers instead of strings, you can do this by adding the `returnBuffers` option.
71
+
72
+
If you handle big numbers, you should pass the `stringNumbers` option. That case numbers above 2^53 can be handled properly without reduced precision.
68
73
69
74
```js
70
75
// Same functions as in the first example
@@ -76,6 +81,8 @@ var parser = new Parser({
76
81
returnError:function(err) {
77
82
lib.returnError(err);
78
83
},
84
+
name:'javascript', // Use the Javascript parser
85
+
stringNumbers:true, // Return all numbers as string instead of a js number
79
86
returnBuffers:true// All strings are returned as buffer e.g. <Buffer 48 65 6c 6c 6f>
Copy file name to clipboardExpand all lines: lib/parser.js
+23-7Lines changed: 23 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ try {
10
10
}catch(err){/* ignore errors */}
11
11
12
12
functionParser(options){
13
-
varparser;
13
+
varparser,msg;
14
14
15
15
if(
16
16
!options||
@@ -21,18 +21,34 @@ function Parser (options) {
21
21
}
22
22
23
23
/* istanbul ignore if: hiredis should always be installed while testing */
24
-
if(options.name==='hiredis'&&!parsers.hiredis){
25
-
console.warn('<< WARNING >> You explicitly required the hiredis parser but hiredis is not installed. The js parser is going to be returned instead.');
24
+
if(options.name==='hiredis'){
25
+
if(!parsers.hiredis){
26
+
msg='You explicitly required the hiredis parser but hiredis is not installed. The JS parser is going to be returned instead.';
27
+
}elseif(options.stringNumbers){
28
+
msg='You explicitly required the hiredis parser in combination with the stringNumbers option. Only the JS parser can handle that and is choosen instead.';
29
+
}
30
+
}elseif(options.name&&!parsers[options.name]){
31
+
msg='The requested parser "'+options.name+'" is unkown and the JS parser is choosen instead.';
0 commit comments