You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
Add option to specify whether to return strings or buffers for bulk data
This commit is contained in:
2
index.js
2
index.js
@@ -110,7 +110,7 @@ function RedisClient(stream, options) {
|
|||||||
self.emitted_end = false;
|
self.emitted_end = false;
|
||||||
|
|
||||||
reply_parser.debug_mode = exports.debug_mode;
|
reply_parser.debug_mode = exports.debug_mode;
|
||||||
self.reply_parser = new reply_parser.Parser();
|
self.reply_parser = new reply_parser.Parser({ return_buffers: false });
|
||||||
// "reply error" is an error sent back by redis
|
// "reply error" is an error sent back by redis
|
||||||
self.reply_parser.on("reply error", function (reply) {
|
self.reply_parser.on("reply error", function (reply) {
|
||||||
self.return_error(reply);
|
self.return_error(reply);
|
||||||
|
@@ -2,7 +2,10 @@ var events = require("events"),
|
|||||||
util = require("../util").util,
|
util = require("../util").util,
|
||||||
hiredis = require("hiredis");
|
hiredis = require("hiredis");
|
||||||
|
|
||||||
function HiredisReplyParser() {
|
function HiredisReplyParser(options) {
|
||||||
|
this.options = options || {};
|
||||||
|
this.return_buffers = this.options.return_buffers;
|
||||||
|
if (this.return_buffers == undefined) this.return_buffers = true;
|
||||||
this.reset();
|
this.reset();
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
@@ -14,7 +17,7 @@ exports.debug_mode = false;
|
|||||||
exports.type = "hiredis";
|
exports.type = "hiredis";
|
||||||
|
|
||||||
HiredisReplyParser.prototype.reset = function() {
|
HiredisReplyParser.prototype.reset = function() {
|
||||||
this.reader = new hiredis.Reader({ return_buffers: true });
|
this.reader = new hiredis.Reader({ return_buffers: this.return_buffers });
|
||||||
}
|
}
|
||||||
|
|
||||||
HiredisReplyParser.prototype.execute = function(data) {
|
HiredisReplyParser.prototype.execute = function(data) {
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
var events = require("events"),
|
var events = require("events"),
|
||||||
util = require("../util").util;
|
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();
|
this.reset();
|
||||||
events.EventEmitter.call(this);
|
events.EventEmitter.call(this);
|
||||||
}
|
}
|
||||||
@@ -245,9 +248,17 @@ RedisReplyParser.prototype.send_error = function (reply) {
|
|||||||
|
|
||||||
RedisReplyParser.prototype.send_reply = function (reply) {
|
RedisReplyParser.prototype.send_reply = function (reply) {
|
||||||
if (this.multi_bulk_length > 0 || this.multi_bulk_nested_length > 0) {
|
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 {
|
} else {
|
||||||
this.emit("reply", reply);
|
if (!this.return_buffers && Buffer.isBuffer(reply)) {
|
||||||
|
this.emit("reply", reply.toString("utf8"));
|
||||||
|
} else {
|
||||||
|
this.emit("reply", reply);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user