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

tests: fix buffer test (failed due to new parser) & remove unused node feature checks (< 4)

This commit is contained in:
Salakar
2020-02-07 00:31:08 +00:00
parent 13ec6afe58
commit 9d65e1c3ed
3 changed files with 8 additions and 34 deletions

View File

@@ -20,11 +20,6 @@ var SUBSCRIBE_COMMANDS = {
punsubscribe: true punsubscribe: true
}; };
// Newer Node.js versions > 0.10 return the EventEmitter right away and using .EventEmitter was deprecated
if (typeof EventEmitter !== 'function') {
EventEmitter = EventEmitter.EventEmitter;
}
function noop () {} function noop () {}
function handle_detect_buffers_reply (reply, command, buffer_args) { function handle_detect_buffers_reply (reply, command, buffer_args) {
@@ -153,7 +148,6 @@ function RedisClient (options, stream) {
this.server_info = {}; this.server_info = {};
this.auth_pass = options.auth_pass || options.password; this.auth_pass = options.auth_pass || options.password;
this.selected_db = options.db; // Save the selected db here, used when reconnecting this.selected_db = options.db; // Save the selected db here, used when reconnecting
this.old_state = null;
this.fire_strings = true; // Determine if strings or buffers should be written to the stream this.fire_strings = true; // Determine if strings or buffers should be written to the stream
this.pipeline = false; this.pipeline = false;
this.sub_commands_left = 0; this.sub_commands_left = 0;
@@ -175,12 +169,6 @@ function RedisClient (options, stream) {
'If you want to keep on listening to this event please listen to the stream drain event directly.' 'If you want to keep on listening to this event please listen to the stream drain event directly.'
); );
} else if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) { } else if ((event === 'message_buffer' || event === 'pmessage_buffer' || event === 'messageBuffer' || event === 'pmessageBuffer') && !this.buffers && !this.message_buffers) {
if (this.reply_parser.name !== 'javascript') {
return this.warn(
'You attached the "' + event + '" listener without the returnBuffers option set to true.\n' +
'Please use the JavaScript parser or set the returnBuffers option to true to return buffers.'
);
}
this.reply_parser.optionReturnBuffers = true; this.reply_parser.optionReturnBuffers = true;
this.message_buffers = true; this.message_buffers = true;
this.handle_reply = handle_detect_buffers_reply; this.handle_reply = handle_detect_buffers_reply;

View File

@@ -4,18 +4,6 @@ var commands = require('redis-commands');
var Multi = require('./multi'); var Multi = require('./multi');
var RedisClient = require('../').RedisClient; var RedisClient = require('../').RedisClient;
var Command = require('./command'); var Command = require('./command');
// Feature detect if a function may change it's name
var changeFunctionName = (function () {
var fn = function abc () {};
try {
Object.defineProperty(fn, 'name', {
value: 'foobar'
});
return true;
} catch (e) {
return false;
}
}());
var addCommand = function (command) { var addCommand = function (command) {
// Some rare Redis commands use special characters in their command name // Some rare Redis commands use special characters in their command name
@@ -61,11 +49,9 @@ var addCommand = function (command) {
if (commandName !== command) { if (commandName !== command) {
RedisClient.prototype[commandName.toUpperCase()] = RedisClient.prototype[commandName] = RedisClient.prototype[command]; RedisClient.prototype[commandName.toUpperCase()] = RedisClient.prototype[commandName] = RedisClient.prototype[command];
} }
if (changeFunctionName) { Object.defineProperty(RedisClient.prototype[command], 'name', {
Object.defineProperty(RedisClient.prototype[command], 'name', { value: commandName
value: commandName });
});
}
} }
// Do not override existing functions // Do not override existing functions
@@ -108,11 +94,9 @@ var addCommand = function (command) {
if (commandName !== command) { if (commandName !== command) {
Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command]; Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command];
} }
if (changeFunctionName) { Object.defineProperty(Multi.prototype[command], 'name', {
Object.defineProperty(Multi.prototype[command], 'name', { value: commandName
value: commandName });
});
}
} }
}; };

View File

@@ -524,6 +524,8 @@ describe('publish/subscribe', function () {
assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect()); assert.strictEqual(channel.inspect(), new Buffer('/foo').inspect());
sub.quit(end); sub.quit(end);
}); });
// Either message_buffers or buffers has to be true, but not both at the same time
assert.notStrictEqual(sub.message_buffers, sub.buffers);
}); });
var batch = sub.batch(); var batch = sub.batch();
batch.psubscribe('*'); batch.psubscribe('*');