

"use strict";
var
  CPP = new (require('childprocess-promise')),
  RedisProto = require('redis-proto'),
  SupportedEvents = null;

class Worker{
  constructor(Socket){
    this.Socket = Socket;
    this.Levels = 0;
    Socket.on('data', Worker.OnData.bind(this));
  }
  static OnData(Buffer){
    Buffer = Buffer.toString();
    let Result = RedisProto.Decode(Buffer);
    if(!Result.length || SupportedEvents.indexOf(Result[0]) === -1){
      this.Socket.write("-ERR unknown command '${Result[0] || ''}'\r\n");
    } else {
      CPP.Request(Result[0], Result).then(function(Response){
        if(Response === '+OK'){
          this.Socket.write(Response + "\r\n");
        } else {
          this.Socket.write(RedisProto.Encode(Response) + "\r\n");
        }
      }.bind(this));
    }
  }
}

process.on('message', function(C, Instance){
  if(C !== 'Server') return ;
  Instance.on('connection', function (Socket){
    new Worker(Socket);
  });
});
CPP.once('SupportedEvents', function(Events){
  SupportedEvents = Events;
});
@@ -544,19 +544,24 @@
 t(Result
-%5B0%5D
+.shift()
 , Result

Remove command name from Request in Worker