Example #1
0
function del(key, callback) {
  key = Utils.transformKey(key, this.options);
  var deleters = this.options.stores.slice(0, this.options.write).map(function(store) {
    return Pea(function(callback) {
      store.del(key, callback);
    });
  });
  Pea.Soup.stir(deleters).then(function(err) {
    callback(null);
  });
}
Example #2
0
function get(key, callback) {
  key = Utils.transformKey(key, this.options);
  var getters = this.options.stores.map(function(store) {
    return Pea(function(callback) {
      store.get(key, function(err, val) {
        if (err || !val) return callback(err || new Error('not found'));
        callback(null, val);
      });
    });
  });
  Pea.Soup.first(getters).then(function(err, val) {
    callback(null, val);
  });
}
Example #3
0
function key(pre, callback) {
  pre = Utils.transformKey(pre, this.options);
  var keyfind = this.options.stores.map(function(store) {
    return Pea(function(callback) {
      store.key(pre, function(err, val) {
        if (err) return callback(err);
        callback(null, Array.isArray(val) ? val : []);
      });
    });
  });
  Pea.Soup.stir(keyfind).then(function(err, vals) {
    var keys = {};
    vals.forEach(function(val) {
      val.forEach(function(item) { keys[item] = true; });
    });
    callback(null, Object.keys(keys).sort());
  });
}