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

enabled adding abritary commands

added test and add_command alias

original and special char commands

tweaked code spacing
This commit is contained in:
Kyle Davis
2016-11-17 15:13:57 -05:00
committed by Ruben Bridgewater
parent 4f7f1adf50
commit 0437aa4985
3 changed files with 55 additions and 9 deletions

View File

@@ -17,11 +17,7 @@ var changeFunctionName = (function () {
}
}());
// TODO: Rewrite this including the invidual commands into a Commands class
// that provided a functionality to add new commands to the client
commands.list.forEach(function (command) {
var addCommand = function (command) {
// Some rare Redis commands use special characters in their command name
// Convert those to a underscore to prevent using invalid function names
var commandName = command.replace(/(?:^([0-9])|[^a-zA-Z0-9_$])/g, '_$1');
@@ -61,8 +57,12 @@ commands.list.forEach(function (command) {
}
return this.internal_send_command(new Command(command, arr, callback));
};
//alias commands with illegal function names (e.g. NR.RUN becomes NR_RUN and nr_run)
if (commandName !== command) {
RedisClient.prototype[commandName.toUpperCase()] = RedisClient.prototype[commandName] = RedisClient.prototype[command];
}
if (changeFunctionName) {
Object.defineProperty(RedisClient.prototype[command], 'name', {
Object.defineProperty(RedisClient.prototype[commandName], 'name', {
value: commandName
});
}
@@ -104,10 +104,18 @@ commands.list.forEach(function (command) {
this.queue.push(new Command(command, arr, callback));
return this;
};
//alias commands with illegal function names (e.g. NR.RUN becomes NR_RUN and nr_run)
if (commandName !== command) {
Multi.prototype[commandName.toUpperCase()] = Multi.prototype[commandName] = Multi.prototype[command];
}
if (changeFunctionName) {
Object.defineProperty(Multi.prototype[command], 'name', {
Object.defineProperty(Multi.prototype[commandName], 'name', {
value: commandName
});
}
}
});
};
commands.list.forEach(addCommand);
module.exports = addCommand;