1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-13 10:02:24 +03:00

feat: accept Map and Set and flatten arguments

This commit is contained in:
Ruben Bridgewater
2017-05-26 10:30:27 +02:00
parent 4182059b7c
commit 6ea202132b
9 changed files with 224 additions and 332 deletions

View File

@@ -5,7 +5,8 @@ const Multi = require('./multi')
const RedisClient = require('../').RedisClient
const Command = require('./command')
const EMPTY_ARRAY = []
const clientProto = RedisClient.prototype
const multiProto = Multi.prototype
// TODO: Rewrite this including the individual commands into a Commands class
// that provided a functionality to add new commands to the client
@@ -15,63 +16,35 @@ commands.list.forEach((command) => {
const commandName = command.replace(/(?:^([0-9])|[^a-zA-Z0-9_$])/g, '_$1')
// Do not override existing functions
if (!RedisClient.prototype[command]) {
RedisClient.prototype[command] = function () {
if (!clientProto[command]) {
clientProto[command] = function () {
const len = arguments.length
var arr, i
if (len === 0) {
arr = EMPTY_ARRAY
} else if (arguments[0].shift) {
arr = arguments[0]
} else if (len > 1 && arguments[1].shift) {
const innerLen = arguments[1].length
arr = new Array(innerLen + 1)
arr[0] = arguments[0]
for (i = 0; i < innerLen; i += 1) {
arr[i + 1] = arguments[1][i]
}
} else {
arr = new Array(len)
for (i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const arr = new Array(len)
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
return this.internalSendCommand(new Command(command, arr))
}
if (RedisClient.prototype[command] !== commandName) {
Object.defineProperty(RedisClient.prototype[command], 'name', {
if (clientProto[command] !== commandName) {
Object.defineProperty(clientProto[command], 'name', {
value: commandName
})
}
}
// Do not override existing functions
if (!Multi.prototype[command]) {
Multi.prototype[command] = function () {
if (!multiProto[command]) {
multiProto[command] = function () {
const len = arguments.length
var arr, i
if (len === 0) {
arr = EMPTY_ARRAY
} else if (arguments[0].shift) {
arr = arguments[0]
} else if (len > 1 && arguments[1].shift) {
const innerLen = arguments[1].length
arr = new Array(innerLen + 1)
arr[0] = arguments[0]
for (i = 0; i < innerLen; i += 1) {
arr[i + 1] = arguments[1][i]
}
} else {
arr = new Array(len)
for (i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
const arr = new Array(len)
for (var i = 0; i < len; i += 1) {
arr[i] = arguments[i]
}
this.queue.push(new Command(command, arr))
return this
}
if (Multi.prototype[command] !== commandName) {
Object.defineProperty(Multi.prototype[command], 'name', {
if (multiProto[command] !== commandName) {
Object.defineProperty(multiProto[command], 'name', {
value: commandName
})
}