# Code coverage report for lib/parsers/hiredis.js

## Statements: 86.36% (19 / 22) Branches: 87.5% (7 / 8) Functions: 100% (3 / 3) Lines: 86.36% (19 / 22) Ignored: none

All files » lib/parsers/ » hiredis.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43

    1

    1
    1
    1
    1

    1
    1

    1
    2
    2
    2
    5
    5

    5
    2

    3

    3

    1
    1
     'use strict';

    var hiredis = require('hiredis');

    function HiredisReplyParser(return_buffers) {
        this.name = exports.name;
        this.return_buffers = return_buffers;
        this.reset();
    }

    HiredisReplyParser.prototype.reset = function () {
        this.reader = new hiredis.Reader({
            return_buffers: this.return_buffers || false
        });
    };

    HiredisReplyParser.prototype.execute = function (data) {
        var reply;
        this.reader.feed(data);
        while (true) {
            try {
                reply = this.reader.get();
            } catch (err) {
                // Protocol errors land here
                this.send_error(err);
                break;
            }

            if (reply === undefined) {
                break;
            }

            Iif (reply && reply.constructor === Error) {
                this.send_error(reply);
            } else {
                this.send_reply(reply);
            }
        }
    };

    exports.Parser = HiredisReplyParser;
    exports.name = 'hiredis';