

"use strict";
var Main = module.parent.exports;

Main.ActionHSET = function(Request){
  if(Request.length < 3){
    throw new Error(Main.MSG_ARGS_LESS);
  }
  Main.ValidateArguments(Main.ARGS_ODD, Request.length);
  let Key = Request.shift();
  let Value = this.Database.get(Key);
  try {
    Main.Validate(Main.VAL_HASH, 'HSET', Value);
  } catch(err){
    Value = new Map();
    this.Database.set(Key, Value);
  }
  for(let Number = 0; Number < Request.length; Number += 2){
    let HValue = Main.NormalizeType(Request[Number + 1]);
    Value.set(Request[Number], HValue);
  }
  return {Type: 'OK'};
};

Main.ActionHGET = function(Request){
  let Key = Request.shift();
  let Value = this.Database.get(Key);

  if(typeof Value !== 'undefined')
    Main.Validate(Main.VAL_HASH, 'HGET', Value);

  if(Request.length === 1){
    return Value && Value.get(Request[0]) || '';
  } else {
    return Request.map(function(Key){
      return Value && Value.get(Key) || '';
    });
  }
};

Main.ActionHDEL = function(Request){
  if(Request.length < 2){
    throw new Error(Main.MSG_ARGS_LESS);
  }
  let Length = 0;
  let Key = Request.shift();
  let Value = this.Database.get(Key);

  if(typeof Value !== 'undefined')
    Main.Validate(Main.VAL_HASH, 'HDEL', Value);
  else
    return Length;

  Request.forEach(function(Name){
    Value.delete(Name);
    Length ++;
  }.bind(this));
  return Length;
};
@@ -1387,12 +1387,830 @@
 n Length;%0A%7D;
+%0A%0AMain.ActionHEXPIRE = function(Request)%7B%0A  Main.ValidateArguments(Main.ARGS_ODD, Request.length);%0A  let Key = Request.shift();%0A  let Value = this.Database.get(Key);%0A  let ToReturn = %7BType: 'OK'%7D;%0A%0A  if(typeof Value !== 'undefined')%0A    Main.Validate(Main.VAL_HASH, 'HEXPIRE', Value);%0A%0A  for(let Number = 0; Number %3C Request.length; Number += 2)%7B%0A    let HKey = Request%5BNumber%5D;%0A    let HTimeout = Main.NormalizeType(Request%5BNumber + 1%5D);%0A    if(typeof HTimeout !== 'number')%0A      throw new Error(%22EXPIRE Expects even parameters to be numeric%22);%0A    let TimeoutKey = Symbol.for(Key + %22%5Cn%22 + HKey);%0A    clearTimeout(this.Timeouts%5BTimeoutKey%5D);%0A    this.Timeouts%5BTimeoutKey%5D = setTimeout(function(HKey)%7B%0A      Main.ActionHDEL.call(this, %5BKey, HKey%5D);%0A    %7D.bind(this, HKey), HTimeout * 1000);%0A  %7D%0A%0A  return ToReturn;%0A%7D;

Implement HEXPIRE