1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-07 13:22:56 +03:00

Add option to specify whether to return strings or buffers for bulk data

This commit is contained in:
Pieter Noordhuis
2010-11-30 23:10:02 +01:00
parent 7b4ca228d6
commit a5381964d9
3 changed files with 20 additions and 6 deletions

View File

@@ -1,7 +1,10 @@
var events = require("events"),
util = require("../util").util;
function RedisReplyParser() {
function RedisReplyParser(options) {
this.options = options || {};
this.return_buffers = this.options.return_buffers;
if (this.return_buffers == undefined) this.return_buffers = true;
this.reset();
events.EventEmitter.call(this);
}
@@ -245,9 +248,17 @@ RedisReplyParser.prototype.send_error = function (reply) {
RedisReplyParser.prototype.send_reply = function (reply) {
if (this.multi_bulk_length > 0 || this.multi_bulk_nested_length > 0) {
this.add_multi_bulk_reply(reply);
if (!this.return_buffers && Buffer.isBuffer(reply)) {
this.add_multi_bulk_reply(reply.toString("utf8"));
} else {
this.add_multi_bulk_reply(reply);
}
} else {
this.emit("reply", reply);
if (!this.return_buffers && Buffer.isBuffer(reply)) {
this.emit("reply", reply.toString("utf8"));
} else {
this.emit("reply", reply);
}
}
};