Ejemplo n.º 1
0
  set(key, val, ttl, fn = noop) {
    const k = `${this.prefix}${key}`;

    if ('function' === typeof ttl) {
      fn = ttl;
      ttl = null;
    }

    try {
      val = JSON.stringify(val)
    } catch (e) {
      return fn(e);
    }

    const cb = err => {
      if (err) return fn(err);
      fn(null, val);
    }

    if (-1 === ttl) {
      this.client.set(k, val, cb);
    } else {
      this.client.setex(k, (ttl || 60), val, cb);
    }
  }