You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
chore: improve new add_command and add documentation
This commit is contained in:
@@ -708,6 +708,12 @@ you can use `send_command()` to send arbitrary commands to Redis.
|
||||
|
||||
All commands are sent as multi-bulk commands. `args` can either be an Array of arguments, or omitted / set to undefined.
|
||||
|
||||
## client.add_command(command_name)
|
||||
|
||||
Calling add_command will add a new command to the prototype. The exact command
|
||||
name will be used when calling using this new command. Using arbitrary arguments
|
||||
is possible as with any other command.
|
||||
|
||||
## client.connected
|
||||
|
||||
Boolean tracking the state of the connection to the Redis server.
|
||||
|
@@ -1,15 +1,17 @@
|
||||
# Changelog
|
||||
|
||||
## v.2.8.0 - 20 Jul, 2017
|
||||
## v.2.8.0 - 31 Jul, 2017
|
||||
|
||||
Features
|
||||
|
||||
- Accept UPPER_CASE commands in send_command
|
||||
- Add arbitrary commands to the prototype by using `Redis.addCommand(name)`
|
||||
|
||||
Bugfixes
|
||||
|
||||
- Fixed not always copying subscribe unsubscribe arguments
|
||||
- Fixed emitting internal errors while reconnecting with auth
|
||||
- Fixed crashing with invalid url option
|
||||
|
||||
## v.2.7.1 - 14 Mar, 2017
|
||||
|
||||
|
@@ -57,12 +57,12 @@ var addCommand = 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)
|
||||
// Alias special 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[commandName], 'name', {
|
||||
Object.defineProperty(RedisClient.prototype[command], 'name', {
|
||||
value: commandName
|
||||
});
|
||||
}
|
||||
@@ -104,12 +104,12 @@ var addCommand = 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)
|
||||
// Alias special 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[commandName], 'name', {
|
||||
Object.defineProperty(Multi.prototype[command], 'name', {
|
||||
value: commandName
|
||||
});
|
||||
}
|
||||
|
@@ -1,36 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
var config = require('../lib/config');
|
||||
var redis = config.redis;
|
||||
var assert = require('assert');
|
||||
|
||||
describe("The 'addCommand/add_command' method", function () {
|
||||
var client = redis.createClient();
|
||||
var testCommands = {
|
||||
newcommand : 'newcommand',
|
||||
nonJsSafe : 'really-new.command',
|
||||
jsSafe : 'really_new_command'
|
||||
};
|
||||
|
||||
it('camel case version exists', function () {
|
||||
assert.strictEqual(typeof redis.addCommand, 'function');
|
||||
});
|
||||
it('snake version exists', function () {
|
||||
assert.strictEqual(typeof redis.add_command, 'function');
|
||||
});
|
||||
it('does not already have the test standard command', function () {
|
||||
assert.strictEqual(client[testCommands.newcommand], undefined);
|
||||
});
|
||||
it('generates a new method for an added command', function () {
|
||||
redis.addCommand(testCommands.newcommand);
|
||||
assert.strictEqual(typeof client[testCommands.newcommand], 'function');
|
||||
});
|
||||
it('does not already have the test non-JS-safe command', function () {
|
||||
assert.strictEqual(client[testCommands.nonJsSafe], undefined);
|
||||
});
|
||||
it('converts illegal command names to JS-safe functions', function () {
|
||||
redis.addCommand(testCommands.nonJsSafe);
|
||||
assert.strictEqual(typeof client[testCommands.jsSafe], 'function');
|
||||
});
|
||||
client.quit();
|
||||
});
|
@@ -12,6 +12,24 @@ var client;
|
||||
|
||||
describe('The node_redis client', function () {
|
||||
|
||||
describe.only("The 'add_command' method", function () {
|
||||
|
||||
it('camel case and snakeCase version exists', function () {
|
||||
assert.strictEqual(typeof redis.addCommand, 'function');
|
||||
assert.strictEqual(typeof redis.add_command, 'function');
|
||||
});
|
||||
|
||||
it('converts special characters in functions names to lowercase', function () {
|
||||
var command = 'really-new.command';
|
||||
assert.strictEqual(redis.prototype[command], undefined);
|
||||
redis.addCommand(command);
|
||||
assert.strictEqual(redis.prototype[command].name, 'really_new_command');
|
||||
assert.strictEqual(redis.prototype[command.toUpperCase()].name, 'really_new_command');
|
||||
assert.strictEqual(redis.prototype.really_new_command.name, 'really_new_command');
|
||||
assert.strictEqual(redis.prototype.REALLY_NEW_COMMAND.name, 'really_new_command');
|
||||
});
|
||||
});
|
||||
|
||||
it('individual commands sanity check', function (done) {
|
||||
// All commands should work the same in multi context or without
|
||||
// Therefor individual commands always have to be handled in both cases
|
||||
|
Reference in New Issue
Block a user