lib/server.js
function command(req, res) {

  this.stats.commands++;

  //console.dir(this);

  // guaranteed to have a string command by connection
  var cmd = req.cmd
    // guaranteed to have an arguments array by connection
    , args = req.args

    // select implementation should guarantee a valid db index
    // on the connection
    , db = this.store.getDatabase(req.conn.db)
    // info object used by the validate function
    , exec = this.execs[cmd]
    , info = {
      db: db, conf: this.conf, conn: req.conn, exec: exec, commands: this.execs}
    // should we queue this command in a transaction
    // of just execute it
    , queue = cmd !== DISCARD && cmd !== EXEC
    // flag if command is acceptable when busy
    , acceptable;

  // raw arguments list, before validation
  // used so that the slowlog does not show modified arguments
  req.raw = args.slice(0);

  //console.error('server processing command: %s', cmd);
  //console.error('server processing command: %j', args);
    //

  if(ScriptManager.busy && !req.script) {
    // compare on command instances
    // in case they have been renamed
    acceptable =
      (exec === Shutdown
       && ('' + args[0] || '').toLowerCase() === NOSAVE)
      || (exec === Script
        && ('' + args[0] || '').toLowerCase() === KILL);
    if(!acceptable) return res.send(StoreError.Busy);
  }

  if(exec === false) {
    return res.send(StoreError.UnknownDisabled);
  }else if(!exec) {
    return res.send(new UnknownCommand(cmd));
  }

  try {
    exec.validate.call(this, cmd, args, info);

    // inject references
    req.db = db;
    req.conf = this.conf;
    req.exec = exec;

    // these properties are available on the req
    delete info.db;
    delete info.conn;
    delete info.conf;

    // inject the info object which is decorated with
    // additional useful information on validation
    req.info = info;

    // alias the command definition
    req.def = req.exec.definition;
  }catch(e) {
    // let the transaction decide how to proceed on error
    if(req.conn.transaction) {
      return req.conn.transaction.add(e, req, res);
    }
    return res.send(e);
  }

  if(req.conn.transaction && queue) {
    return req.conn.transaction.add(null, req, res);
  }

  this.execute(exec, req, res);

}
function command(req, res) {

  this.stats.commands++;

  //console.dir(this);

  // guaranteed to have a string command by connection
  var cmd = req.cmd
    // guaranteed to have an arguments array by connection
    , args = req.args

    // select implementation should guarantee a valid db index
    // on the connection
    , db = this.store.getDatabase(req.conn.db)
    // info object used by the validate function
    , exec = this.execs[cmd]
    , info = {
      db: db, conf: this.conf, conn: req.conn, exec: exec, commands: this.execs}
    // should we queue this command in a transaction
    // of just execute it
    , queue = cmd !== DISCARD && cmd !== EXEC
    // flag if command is acceptable when busy
    , acceptable;

  // raw arguments list, before validation
  // used so that the slowlog does not show modified arguments
  req.raw = args.slice(0);

  //console.error('server processing command: %s', cmd);
  //console.error('server processing command: %j', args);
    //

  if(ScriptManager.busy && !req.script) {
    // compare on command instances
    // in case they have been renamed
    acceptable =
      (exec === Shutdown
       && ('' + args[0] || '').toLowerCase() === NOSAVE)
      || (exec === Script
        && ('' + args[0] || '').toLowerCase() === KILL);
    if(!acceptable) return res.send(StoreError.Busy);
  }

  if(exec === false) {
    return res.send(StoreError.UnknownDisabled);
  }else if(!exec) {
    return res.send(new UnknownCommand(cmd));
  }

  try {
    exec.validate.call(this, cmd, args, info);

    // inject references
    req.db = db;
    req.conf = this.conf;
    req.exec = exec;

    // these properties are available on the req
    delete info.db;
    delete info.conn;
    delete info.conf;

    // inject the info object which is decorated with
    // additional useful information on validation
    req.info = info;

    // alias the command definition
    req.def = req.exec.definition;
  }catch(e) {
    // let the transaction decide how to proceed on error
    if(req.conn.transaction) {
      return req.conn.transaction.add(e, req, res);
    }
    return res.send(e);
  }

  if(req.conn.transaction && queue) {
    return req.conn.transaction.add(null, req, res);
  }

  this.execute(exec, req, res);

}
function command ( req , res ) { this . stats . commands ++ ; //console.dir(this); // guaranteed to have a string command by connection var cmd = req . cmd // guaranteed to have an arguments array by connection , args = req . args // select implementation should guarantee a valid db index // on the connection , db = this . store . getDatabase ( req . conn . db ) // info object used by the validate function , exec = this . execs [ cmd ] , info = { db : db , conf : this . conf , conn : req . conn , exec : exec , commands : this . execs } // should we queue this command in a transaction // of just execute it , queue = cmd !== DISCARD && cmd !== EXEC // flag if command is acceptable when busy , acceptable ; // raw arguments list, before validation // used so that the slowlog does not show modified arguments req . raw = args . slice ( 0 ) ; //console.error('server processing command: %s', cmd); //console.error('server processing command: %j', args); // if ( ScriptManager . busy && ! req . script ) { // compare on command instances // in case they have been renamed acceptable = ( exec === Shutdown && ( '' + args [ 0 ] || '' ) . toLowerCase ( ) === NOSAVE ) || ( exec === Script && ( '' + args [ 0 ] || '' ) . toLowerCase ( ) === KILL ) ; if ( ! acceptable ) return res . send ( StoreError . Busy ) ; } if ( exec === false ) { return res . send ( StoreError . UnknownDisabled ) ; } else if ( ! exec ) { return res . send ( new UnknownCommand ( cmd ) ) ; } try { exec . validate . call ( this , cmd , args , info ) ; // inject references req . db = db ; req . conf = this . conf ; req . exec = exec ; // these properties are available on the req delete info . db ; delete info . conn ; delete info . conf ; // inject the info object which is decorated with // additional useful information on validation req . info = info ; // alias the command definition req . def = req . exec . definition ; } catch ( e ) { // let the transaction decide how to proceed on error if ( req . conn . transaction ) { return req . conn . transaction . add ( e , req , res ) ; } return res . send ( e ) ; } if ( req . conn . transaction && queue ) { return req . conn . transaction . add ( null , req , res ) ; } this . execute ( exec , req , res ) ; }
Process an incoming command.

@param req The connection request.
@param res The connection response.
Process an incoming command .