lib/validators/arity.js
function arity(cmd, args, info, sub) {
  var subcommand = sub !== undefined;

  // command validation decorated the info
  var def = sub || info.command.def
    , expected = def.arity
    , first = def.first
    , last = def.last
    , step = def.step
    , min = Math.abs(expected)
    , max
    // account for command, redis includes command
    // in the arity
    , count = args.length + 1;

  //console.dir(def);

  // only command is allowed - zero args (COMMAND etc)
  if(expected === 0 && first === 0 && last === 0) {
    min = max = 1;
  // positive fixed args length (TYPE etc)
  }else if(expected > 0) {
    min = max = expected;
  // variable length arguments (MGET/MSET etc)
  }else{
    max = Number.MAX_VALUE;
    // test for step
    if(step > 1 && (args.length % step !== 0)) {
      throw new CommandArgLength(cmd);
    }
  }

  // made it this far, check subcommands
  // for commands that require a subcommand
  if(!subcommand && Constants.SUBCOMMAND[cmd] && args.length && arity !== 1) {
    sub = Constants.SUBCOMMAND[cmd][args[0]];
    arity(args[0], args.slice(1), info, sub);
  }else if(count < min || count > max) {
    if(subcommand) throw UnknownSubcommand;
    throw new CommandArgLength(cmd);
  }

  return true;
}
function arity(cmd, args, info, sub) {
  var subcommand = sub !== undefined;

  // command validation decorated the info
  var def = sub || info.command.def
    , expected = def.arity
    , first = def.first
    , last = def.last
    , step = def.step
    , min = Math.abs(expected)
    , max
    // account for command, redis includes command
    // in the arity
    , count = args.length + 1;

  //console.dir(def);

  // only command is allowed - zero args (COMMAND etc)
  if(expected === 0 && first === 0 && last === 0) {
    min = max = 1;
  // positive fixed args length (TYPE etc)
  }else if(expected > 0) {
    min = max = expected;
  // variable length arguments (MGET/MSET etc)
  }else{
    max = Number.MAX_VALUE;
    // test for step
    if(step > 1 && (args.length % step !== 0)) {
      throw new CommandArgLength(cmd);
    }
  }

  // made it this far, check subcommands
  // for commands that require a subcommand
  if(!subcommand && Constants.SUBCOMMAND[cmd] && args.length && arity !== 1) {
    sub = Constants.SUBCOMMAND[cmd][args[0]];
    arity(args[0], args.slice(1), info, sub);
  }else if(count < min || count > max) {
    if(subcommand) throw UnknownSubcommand;
    throw new CommandArgLength(cmd);
  }

  return true;
}
function arity ( cmd , args , info , sub ) { var subcommand = sub !== undefined ; // command validation decorated the info var def = sub || info . command . def , expected = def . arity , first = def . first , last = def . last , step = def . step , min = Math . abs ( expected ) , max // account for command, redis includes command // in the arity , count = args . length + 1 ; //console.dir(def); // only command is allowed - zero args (COMMAND etc) if ( expected === 0 && first === 0 && last === 0 ) { min = max = 1 ; // positive fixed args length (TYPE etc) } else if ( expected > 0 ) { min = max = expected ; // variable length arguments (MGET/MSET etc) } else { max = Number . MAX_VALUE ; // test for step if ( step > 1 && ( args . length % step !== 0 ) ) { throw new CommandArgLength ( cmd ) ; } } // made it this far, check subcommands // for commands that require a subcommand if ( ! subcommand && Constants . SUBCOMMAND [ cmd ] && args . length && arity !== 1 ) { sub = Constants . SUBCOMMAND [ cmd ] [ args [ 0 ] ] ; arity ( args [ 0 ] , args . slice ( 1 ) , info , sub ) ; } else if ( count < min || count > max ) { if ( subcommand ) throw UnknownSubcommand ; throw new CommandArgLength ( cmd ) ; } return true ; }
Validate argument length.

@param cmd The command name (lowercase).
@param args The command arguments, must be an array.
@param info The server information.
Validate argument length .