Example #1
0
Cache.prototype.remove = function (key, cb) {
  var thisOptions = this.options;
  var prefix = this.options.prefix;
  var keys = [];
  if (typeof key === 'object') {
    for (var i = 0; i < key.length; i++) {
      keys.push(md5(prefix + key[i]));
    }
  } else {
    keys = [ md5(prefix + key)];
  }
  var self = this;
  var paralle = [];
  paralle.push(function () {
    self.storage.del(keys, this);
  });
  paralle.push(function () {
    if (typeof key === 'string') {
      key = [key];
    }
    var params = [ thisOptions.keyset_key ].concat(key);
    params.push(this);
    self.storage.srem.apply(self.storage, params);
  });
  ep().lazy(paralle, function () { cb && cb(null) }).on('error', function (err) { cb && cb(err) }).run();
}
Example #2
0
Cache.prototype._initRedis = function (cb) {
  var options = this.options;
  try {
    this.storage = mredis.createClient(options);
  } catch (err) {
    return cb(err);
  }
  var self = this;
  var pipe = ep();
  if (options.password) {
    pipe.seq(function () {
      self.storage.auth(options.password, this);
    });
  }
  pipe.seq(function () {
    self.storage.select(options.db || 0, cb || noop);
  });
  pipe.run();
}
Example #3
0
Cache.prototype.set = function (key, value, options, cb) {
  if (typeof options === 'function') {
    cb = options;
    options = {expire: this.options.expire};
  }
  options = options || this.options;
  var thisOptions = this.options;
  var kname = thisOptions.prefix + key;
  var k = md5(kname);
  var paralle = [];
  var self = this;

  paralle.push(function () {
    self.storage.setex(k, options.expire, value, this);
  });
  paralle.push(function () {
    self.storage.sadd(thisOptions.keyset_key, kname, this);
  });
  ep().lazy(paralle, function () { cb && cb(null) }).on('error', function (err) { cb && cb(err) }).run();
};
Example #4
0
 del: function (keys, callback) {
   var flag = 0;
   var func = function () {
     var key = keys[flag++];
     // tair 无delete 接口,设为空且失效时间为 1s
     tair.put(key, null, {expired: 1}, this);
   };
   var tasks = [];
   for (var i = 0, len = keys.length; i < len; i++) {
     tasks.push(func);
   }
   var e = ep();
   e.on('error', function (err) {
     return callback && callback(err);
   });
   e.lazy(tasks);
   e.lazy(function () {
     return callback && callback(null);
   });
   e.run();
 },