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

A function name is only configurable from v8 >= v.4.3

This commit is contained in:
Ruben Bridgewater
2016-05-28 14:57:31 +02:00
parent 25aa8f6710
commit ce44213d65
2 changed files with 23 additions and 7 deletions

View File

@@ -10,7 +10,7 @@ Features
- Updated [redis-parser](https://github.com/NodeRedis/redis-parser) dependency ([changelog](https://github.com/NodeRedis/redis-parser/releases/tag/v.2.0.0)) - Updated [redis-parser](https://github.com/NodeRedis/redis-parser) dependency ([changelog](https://github.com/NodeRedis/redis-parser/releases/tag/v.2.0.0))
- The JS parser is from now on the new default as it is a lot faster than the hiredis parser - The JS parser is from now on the new default as it is a lot faster than the hiredis parser
- This is no BC as there is no changed behavior for the user at all but just a performance improvement. Explicitly requireing the Hiredis parser is still possible. - This is no BC as there is no changed behavior for the user at all but just a performance improvement. Explicitly requireing the Hiredis parser is still possible.
- Added name property to all Redis functions - Added name property to all Redis functions (Node.js >= 4.0)
Bugfixes Bugfixes

View File

@@ -4,6 +4,18 @@ 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;
}
}());
// TODO: Rewrite this including the invidual commands into a Commands class // TODO: Rewrite this including the invidual commands into a Commands class
// that provided a functionality to add new commands to the client // that provided a functionality to add new commands to the client
@@ -45,10 +57,12 @@ commands.list.forEach(function (command) {
} }
return this.internal_send_command(new Command(command, arr, callback)); return this.internal_send_command(new Command(command, arr, callback));
}; };
if (changeFunctionName) {
Object.defineProperty(RedisClient.prototype[command], 'name', { Object.defineProperty(RedisClient.prototype[command], 'name', {
value: command value: command
}); });
} }
}
// Do not override existing functions // Do not override existing functions
if (!Multi.prototype[command]) { if (!Multi.prototype[command]) {
@@ -86,8 +100,10 @@ commands.list.forEach(function (command) {
this.queue.push(new Command(command, arr, callback)); this.queue.push(new Command(command, arr, callback));
return this; return this;
}; };
if (changeFunctionName) {
Object.defineProperty(Multi.prototype[command], 'name', { Object.defineProperty(Multi.prototype[command], 'name', {
value: command value: command
}); });
} }
}
}); });