/****************************************************/
/*         PHPSession - v0.1.3                      */
/*                                                  */
/*         Manage $_SESSION var in node.js          */
/****************************************************/
/*             -    Copyright 2015    -             */
/*                                                  */
/*   License: Apache v 2.0                          */
/*   @Author: Ben Mz                                */
/*   @Email: bmz (at) certiwise (dot) com           */
/*                                                  */
/****************************************************/

(function() {
  var Memcached, PHPSession;

  Memcached = require('memcached');

  module.exports = PHPSession = (function() {
    function PHPSession(_arg) {
      var host, port;
      host = _arg.host, port = _arg.port;
      if (host == null) {
        host = '127.0.0.1';
      }
      if (port == null) {
        port = '11211';
      }
      this.mem = new Memcached("" + host + ":" + port);
    }

    PHPSession.prototype.get = function(_arg) {
      var cb, id, session;
      id = _arg.id, cb = _arg.cb;
      session = '';
      return this.mem.get("sessions/" + id, (function(_this) {
        return function(err, raw) {
          if ((err != null) || (raw == null) || raw.length === 0) {
            return cb();
          } else {
            session = JSON.parse(raw);
            return cb(session);
          }
        };
      })(this));
    };

    PHPSession.prototype.set = function(_arg) {
      var cb, id, json, lifetime;
      id = _arg.id, json = _arg.json, lifetime = _arg.lifetime, cb = _arg.cb;
      if (id == null) {
        return;
      }
      if (lifetime == null) {
        lifetime = 1440;
      }
      if (cb == null) {
        cb = console.log;
      }
      return this.get({
        id: id,
        cb: (function(_this) {
          return function(session) {
            var content;
            if (session != null) {
              content = JSON.stringify(json);
              return _this.mem.set("sessions/" + id, content, lifetime, function(err) {
                if (err != null) {
                  return cb(err);
                } else {
                  return cb();
                }
              });
            } else {
              return cb('ERRNOSESS');
            }
          };
        })(this)
      });
    };

    PHPSession.prototype.update = function(_arg) {
      var cb, id, key, lifetime, value;
      id = _arg.id, key = _arg.key, value = _arg.value, lifetime = _arg.lifetime, cb = _arg.cb;
      if (!((key != null) && (id != null))) {
        return;
      }
      if (lifetime == null) {
        lifetime = 1440;
      }
      if (cb == null) {
        cb = console.log;
      }
      return this.get({
        id: id,
        cb: (function(_this) {
          return function(session) {
            var content;
            if (session != null) {
              session[key] = value;
              content = JSON.stringify(session);
              return _this.mem.set("sessions/" + id, content, lifetime, function(err) {
                if (err != null) {
                  return cb(err);
                } else {
                  return cb();
                }
              });
            } else {
              return cb('ERRNOSESS');
            }
          };
        })(this)
      });
    };

    PHPSession.prototype["delete"] = function(_arg) {
      var cb, id;
      id = _arg.id, cb = _arg.cb;
      if (id == null) {
        return;
      }
      if (cb == null) {
        cb = console.log;
      }
      return this.get({
        id: id,
        cb: (function(_this) {
          return function(session) {
            if (session != null) {
              return _this.set({
                id: id,
                raw: null,
                lifetime: 0,
                cb: cb
              });
            } else {
              return cb('ERRNOSESS');
            }
          };
        })(this)
      });
    };

    return PHPSession;

  })();

}).call(this);

@@ -81,9 +81,9 @@
 0.1.
-3
+4
     
@@ -1695,32 +1695,60 @@
  (id == null) %7B%0A
+        cb('ERRMISSPARAM');%0A
         return;%0A
@@ -2689,24 +2689,52 @@
 = null))) %7B%0A
+        cb('ERRMISSPARAM');%0A
         retu
@@ -3611,32 +3611,60 @@
  (id == null) %7B%0A
+        cb('ERRMISSPARAM');%0A
         return;%0A
@@ -3903,64 +3903,118 @@
 his.
-set(%7B%0A                id: id,%0A                raw: null,
+mem.del(%22sessions/%22 + id, function(err) %7B%0A                if (err != null) %7B%0A                  return cb(err);
 %0A   
@@ -4030,21 +4030,18 @@
     
-lifetime: 0,%0A
+%7D else %7B%0A 
     
@@ -4056,14 +4056,39 @@
     
-cb: cb
+ return cb();%0A                %7D
 %0A   

Use memcahced delete method