Socket
Socket
Sign inDemoInstall

cache-manager-redis-store

Package Overview
Dependencies
10
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

dist/index.d.ts

1004

dist/index.js
'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
Object.defineProperty(exports, '__esModule', { value: true });
var Redis = _interopDefault(require('redis'));
var node_util = require('node:util');
var redis = require('redis');
var redisStore = function redisStore() {
var redisCache = Redis.createClient.apply(Redis, arguments);
var storeArgs = redisCache.options;
return {
name: 'redis',
getClient: function getClient() {
return redisCache;
},
set: function set(key, value, options, cb) {
var self = this;
return new Promise(function (resolve, reject) {
if (typeof options === 'function') {
cb = options;
options = {};
function _regeneratorRuntime() {
_regeneratorRuntime = function () {
return exports;
};
var exports = {},
Op = Object.prototype,
hasOwn = Op.hasOwnProperty,
$Symbol = "function" == typeof Symbol ? Symbol : {},
iteratorSymbol = $Symbol.iterator || "@@iterator",
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
function define(obj, key, value) {
return Object.defineProperty(obj, key, {
value: value,
enumerable: !0,
configurable: !0,
writable: !0
}), obj[key];
}
try {
define({}, "");
} catch (err) {
define = function (obj, key, value) {
return obj[key] = value;
};
}
function wrap(innerFn, outerFn, self, tryLocsList) {
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
generator = Object.create(protoGenerator.prototype),
context = new Context(tryLocsList || []);
return generator._invoke = function (innerFn, self, context) {
var state = "suspendedStart";
return function (method, arg) {
if ("executing" === state) throw new Error("Generator is already running");
if ("completed" === state) {
if ("throw" === method) throw arg;
return doneResult();
}
options = options || {};
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
for (context.method = method, context.arg = arg;;) {
var delegate = context.delegate;
if (delegate) {
var delegateResult = maybeInvokeDelegate(delegate, context);
if (delegateResult) {
if (delegateResult === ContinueSentinel) continue;
return delegateResult;
}
}
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
if ("suspendedStart" === state) throw state = "completed", context.arg;
context.dispatchException(context.arg);
} else "return" === context.method && context.abrupt("return", context.arg);
state = "executing";
var record = tryCatch(innerFn, self, context);
if ("normal" === record.type) {
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
return {
value: record.arg,
done: context.done
};
}
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
}
};
}(innerFn, self, context), generator;
}
function tryCatch(fn, obj, arg) {
try {
return {
type: "normal",
arg: fn.call(obj, arg)
};
} catch (err) {
return {
type: "throw",
arg: err
};
}
}
exports.wrap = wrap;
var ContinueSentinel = {};
function Generator() {}
function GeneratorFunction() {}
function GeneratorFunctionPrototype() {}
var IteratorPrototype = {};
define(IteratorPrototype, iteratorSymbol, function () {
return this;
});
var getProto = Object.getPrototypeOf,
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
function defineIteratorMethods(prototype) {
["next", "throw", "return"].forEach(function (method) {
define(prototype, method, function (arg) {
return this._invoke(method, arg);
});
});
}
function AsyncIterator(generator, PromiseImpl) {
function invoke(method, arg, resolve, reject) {
var record = tryCatch(generator[method], generator, arg);
if ("throw" !== record.type) {
var result = record.arg,
value = result.value;
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
invoke("next", value, resolve, reject);
}, function (err) {
invoke("throw", err, resolve, reject);
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
result.value = unwrapped, resolve(result);
}, function (error) {
return invoke("throw", error, resolve, reject);
});
}
reject(record.arg);
}
var previousPromise;
this._invoke = function (method, arg) {
function callInvokeWithMethodAndArg() {
return new PromiseImpl(function (resolve, reject) {
invoke(method, arg, resolve, reject);
});
}
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
};
}
function maybeInvokeDelegate(delegate, context) {
var method = delegate.iterator[context.method];
if (undefined === method) {
if (context.delegate = null, "throw" === context.method) {
if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
}
return ContinueSentinel;
}
var record = tryCatch(method, delegate.iterator, context.arg);
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
var info = record.arg;
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
}
function pushTryEntry(locs) {
var entry = {
tryLoc: locs[0]
};
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
}
function resetTryEntry(entry) {
var record = entry.completion || {};
record.type = "normal", delete record.arg, entry.completion = record;
}
function Context(tryLocsList) {
this.tryEntries = [{
tryLoc: "root"
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
}
function values(iterable) {
if (iterable) {
var iteratorMethod = iterable[iteratorSymbol];
if (iteratorMethod) return iteratorMethod.call(iterable);
if ("function" == typeof iterable.next) return iterable;
if (!isNaN(iterable.length)) {
var i = -1,
next = function next() {
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
return next.value = undefined, next.done = !0, next;
};
return next.next = next;
}
}
return {
next: doneResult
};
}
function doneResult() {
return {
value: undefined,
done: !0
};
}
return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
var ctor = "function" == typeof genFun && genFun.constructor;
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
}, exports.mark = function (genFun) {
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
}, exports.awrap = function (arg) {
return {
__await: arg
};
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
return this;
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
void 0 === PromiseImpl && (PromiseImpl = Promise);
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
return result.done ? result.value : iter.next();
});
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
return this;
}), define(Gp, "toString", function () {
return "[object Generator]";
}), exports.keys = function (object) {
var keys = [];
for (var key in object) keys.push(key);
return keys.reverse(), function next() {
for (; keys.length;) {
var key = keys.pop();
if (key in object) return next.value = key, next.done = !1, next;
}
return next.done = !0, next;
};
}, exports.values = values, Context.prototype = {
constructor: Context,
reset: function (skipTempReset) {
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
},
stop: function () {
this.done = !0;
var rootRecord = this.tryEntries[0].completion;
if ("throw" === rootRecord.type) throw rootRecord.arg;
return this.rval;
},
dispatchException: function (exception) {
if (this.done) throw exception;
var context = this;
function handle(loc, caught) {
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
}
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i],
record = entry.completion;
if ("root" === entry.tryLoc) return handle("end");
if (entry.tryLoc <= this.prev) {
var hasCatch = hasOwn.call(entry, "catchLoc"),
hasFinally = hasOwn.call(entry, "finallyLoc");
if (hasCatch && hasFinally) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
} else if (hasCatch) {
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
} else {
if (!hasFinally) throw new Error("try statement without catch or finally");
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
}
}
if (!self.isCacheableValue(value)) {
return cb(new Error("\"".concat(value, "\" is not a cacheable value")));
}
},
abrupt: function (type, arg) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
var finallyEntry = entry;
break;
}
var ttl = options.ttl || options.ttl === 0 ? options.ttl : storeArgs.ttl;
var val = JSON.stringify(value) || '"undefined"';
if (ttl) {
redisCache.setex(key, ttl, val, handleResponse(cb));
} else {
redisCache.set(key, val, handleResponse(cb));
}
});
}
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
var record = finallyEntry ? finallyEntry.completion : {};
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
},
mset: function mset() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
complete: function (record, afterLoc) {
if ("throw" === record.type) throw record.arg;
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
},
finish: function (finallyLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
}
var self = this;
return new Promise(function (resolve, reject) {
var cb;
var options = {};
if (typeof args[args.length - 1] === 'function') {
cb = args.pop();
},
catch: function (tryLoc) {
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
var entry = this.tryEntries[i];
if (entry.tryLoc === tryLoc) {
var record = entry.completion;
if ("throw" === record.type) {
var thrown = record.arg;
resetTryEntry(entry);
}
return thrown;
}
}
throw new Error("illegal catch attempt");
},
delegateYield: function (iterable, resultName, nextLoc) {
return this.delegate = {
iterator: values(iterable),
resultName: resultName,
nextLoc: nextLoc
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
}
}, exports;
}
function _typeof(obj) {
"@babel/helpers - typeof";
if (args[args.length - 1] instanceof Object && args[args.length - 1].constructor === Object) {
options = args.pop();
}
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
}, _typeof(obj);
}
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _asyncToGenerator(fn) {
return function () {
var self = this,
args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function _next(value) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
}
function _throw(err) {
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
}
_next(undefined);
});
};
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length) return {
done: true
};
}
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = it.call(o);
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
}
};
}
var ttl = options.ttl || options.ttl === 0 ? options.ttl : storeArgs.ttl;
var multi;
if (ttl) {
multi = redisCache.multi();
function redisStore(_x) {
return _redisStore.apply(this, arguments);
}
function _redisStore() {
_redisStore = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(config) {
var redisCache;
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
redisCache = redis.createClient(config);
_context10.next = 3;
return redisCache.connect();
case 3:
return _context10.abrupt("return", buildRedisStoreWithConfig(redisCache, config));
case 4:
case "end":
return _context10.stop();
}
var key;
var value;
var parsed = [];
for (var i = 0; i < args.length; i += 2) {
key = args[i];
value = args[i + 1];
/**
* Make sure the value is cacheable
*/
if (!self.isCacheableValue(value)) {
return cb(new Error("\"".concat(value, "\" is not a cacheable value")));
}
}, _callee10);
}));
return _redisStore.apply(this, arguments);
}
var buildRedisStoreWithConfig = function buildRedisStoreWithConfig(redisCache, config) {
var isCacheableValue = config.isCacheableValue || function (value) {
return value !== undefined && value !== null;
};
var _set = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(key, value, options) {
var ttl;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (isCacheableValue(value)) {
_context.next = 2;
break;
}
throw new Error("\"".concat(value, "\" is not a cacheable value"));
case 2:
ttl = options !== null && options !== void 0 && options.ttl || (options === null || options === void 0 ? void 0 : options.ttl) === 0 ? options.ttl : config.ttl;
if (!ttl) {
_context.next = 7;
break;
}
return _context.abrupt("return", redisCache.setEx(key, ttl, getValue(value)));
case 7:
return _context.abrupt("return", redisCache.set(key, getValue(value)));
case 8:
case "end":
return _context.stop();
}
value = JSON.stringify(value) || '"undefined"';
parsed.push.apply(parsed, [key, value]);
if (ttl) {
multi.setex(key, ttl, value);
}
}, _callee);
}));
return function set(_x2, _x3, _x4) {
return _ref.apply(this, arguments);
};
}();
var _get = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key, options) {
var val;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return redisCache.get(key);
case 2:
val = _context2.sent;
if (!(val === null)) {
_context2.next = 5;
break;
}
return _context2.abrupt("return", null);
case 5:
return _context2.abrupt("return", options.parse !== false ? JSON.parse(val) : val);
case 6:
case "end":
return _context2.stop();
}
}
if (ttl) {
multi.exec(handleResponse(cb));
} else {
redisCache.mset.apply(redisCache, [].concat(parsed, [handleResponse(cb)]));
}, _callee2);
}));
return function get(_x5, _x6) {
return _ref2.apply(this, arguments);
};
}();
var _del = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(args) {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
return _context3.abrupt("return", redisCache.del(args));
case 1:
case "end":
return _context3.stop();
}
}
});
},
get: function get(key, options, cb) {
return new Promise(function (resolve, reject) {
if (typeof options === 'function') {
cb = options;
}, _callee3);
}));
return function del(_x7) {
return _ref3.apply(this, arguments);
};
}();
var _mset = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(args) {
var _options, _options2;
var options, ttl, items, multi, _iterator, _step, kv, _kv, key, value;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
if (isObject(args.at(-1))) {
options = args.pop();
}
ttl = (_options = options) !== null && _options !== void 0 && _options.ttl || ((_options2 = options) === null || _options2 === void 0 ? void 0 : _options2.ttl) === 0 ? options.ttl : config.ttl; // Zips even and odd array items into tuples
items = args.map(function (key, index) {
if (index % 2 !== 0) return null;
var value = args[index + 1];
if (!isCacheableValue(value)) {
throw new Error("\"".concat(value, "\" is not a cacheable value"));
}
return [key, getValue(value)];
}).filter(function (key) {
return key !== null;
});
if (!ttl) {
_context4.next = 10;
break;
}
multi = redisCache.multi();
_iterator = _createForOfIteratorHelper(items);
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
kv = _step.value;
_kv = _slicedToArray(kv, 2), key = _kv[0], value = _kv[1];
multi.setEx(key, ttl, value);
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
return _context4.abrupt("return", multi.exec());
case 10:
return _context4.abrupt("return", redisCache.mSet(items));
case 11:
case "end":
return _context4.stop();
}
}
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
};
}, _callee4);
}));
return function mset(_x8) {
return _ref4.apply(this, arguments);
};
}();
var _mget = /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
var options,
_len,
args,
_key,
_args5 = arguments;
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
options = {};
for (_len = _args5.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = _args5[_key];
}
if (isObject(args.at(-1))) {
options = args.pop();
}
return _context5.abrupt("return", redisCache.mGet(args).then(function (res) {
return res.map(function (val) {
if (val === null) {
return null;
}
return options.parse !== false ? JSON.parse(val) : val;
});
}));
case 4:
case "end":
return _context5.stop();
}
}
redisCache.get(key, handleResponse(cb, {
parse: true
}));
});
},
mget: function mget() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return new Promise(function (resolve, reject) {
var cb;
var options = {};
if (typeof args[args.length - 1] === 'function') {
cb = args.pop();
}, _callee5);
}));
return function mget() {
return _ref5.apply(this, arguments);
};
}();
var _mdel = /*#__PURE__*/function () {
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
var _len2,
args,
_key2,
_args6 = arguments;
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
for (_len2 = _args6.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = _args6[_key2];
}
if (Array.isArray(args)) {
args = args.flat();
}
return _context6.abrupt("return", redisCache.del(args));
case 3:
case "end":
return _context6.stop();
}
}
if (args[args.length - 1] instanceof Object && args[args.length - 1].constructor === Object) {
options = args.pop();
}, _callee6);
}));
return function mdel() {
return _ref6.apply(this, arguments);
};
}();
var _reset = /*#__PURE__*/function () {
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
return _context7.abrupt("return", redisCache.flushDb());
case 1:
case "end":
return _context7.stop();
}
}
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
};
}, _callee7);
}));
return function reset() {
return _ref7.apply(this, arguments);
};
}();
var _keys = /*#__PURE__*/function () {
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(pattern) {
return _regeneratorRuntime().wrap(function _callee8$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
return _context8.abrupt("return", redisCache.keys(pattern));
case 1:
case "end":
return _context8.stop();
}
}
redisCache.mget.apply(redisCache, [].concat(args, [handleResponse(cb, {
parse: true
})]));
});
}, _callee8);
}));
return function keys(_x9) {
return _ref8.apply(this, arguments);
};
}();
var _ttl = /*#__PURE__*/function () {
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(key) {
return _regeneratorRuntime().wrap(function _callee9$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
return _context9.abrupt("return", redisCache.ttl(key));
case 1:
case "end":
return _context9.stop();
}
}
}, _callee9);
}));
return function ttl(_x10) {
return _ref9.apply(this, arguments);
};
}();
return {
name: 'redis',
getClient: function getClient() {
return redisCache;
},
isCacheableValue: isCacheableValue,
set: function set(key, value, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
options = options || {};
if (typeof cb === 'function') {
node_util.callbackify(_set)(key, value, options, cb);
} else {
return _set(key, value, options);
}
},
get: function get(key, options, cb) {
if (typeof options === 'function') {
cb = options;
options = {};
}
options = options || {};
if (typeof cb === 'function') {
node_util.callbackify(_get)(key, options, cb);
} else {
return _get(key, options);
}
},
del: function del() {

@@ -155,34 +749,52 @@ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {

}
return new Promise(function (resolve, reject) {
var cb;
var options = {};
if (typeof args[args.length - 1] === 'function') {
cb = args.pop();
}
if (args[args.length - 1] instanceof Object && args[args.length - 1].constructor === Object) {
options = args.pop();
}
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
};
}
redisCache.del.apply(redisCache, [].concat(args, [handleResponse(cb)]));
});
if (typeof args.at(-1) === 'function') {
var cb = args.pop();
node_util.callbackify(_del)(args, cb);
} else {
return _del(args);
}
},
mset: function mset() {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
if (typeof args.at(-1) === 'function') {
var cb = args.pop();
node_util.callbackify(_mset)(args, cb);
} else {
return _mset(args);
}
},
mget: function mget() {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
if (typeof args.at(-1) === 'function') {
var cb = args.pop();
node_util.callbackify(function () {
return _mget.apply(void 0, args);
})(cb);
} else {
return _mget.apply(void 0, args);
}
},
mdel: function mdel() {
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
args[_key6] = arguments[_key6];
}
if (typeof args.at(-1) === 'function') {
var cb = args.pop();
node_util.callbackify(function () {
return _mdel.apply(void 0, args);
})(cb);
} else {
return _mdel.apply(void 0, args);
}
},
reset: function reset(cb) {
return new Promise(function (resolve, reject) {
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
};
}
redisCache.flushdb(handleResponse(cb));
});
if (typeof cb === 'function') {
node_util.callbackify(_reset)(cb);
} else {
return _reset();
}
},

@@ -192,70 +804,28 @@ keys: function keys() {

var cb = arguments.length > 1 ? arguments[1] : undefined;
return new Promise(function (resolve, reject) {
if (typeof pattern === 'function') {
cb = pattern;
pattern = '*';
}
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
};
}
redisCache.keys(pattern, handleResponse(cb));
});
if (typeof cb === 'function') {
node_util.callbackify(function () {
return _keys(pattern);
})(cb);
} else {
return _keys(pattern);
}
},
ttl: function ttl(key, cb) {
return new Promise(function (resolve, reject) {
if (!cb) {
cb = function cb(err, result) {
return err ? reject(err) : resolve(result);
};
}
redisCache.ttl(key, handleResponse(cb));
});
},
isCacheableValue: storeArgs.is_cacheable_value || function (value) {
return value !== undefined && value !== null;
if (typeof cb === 'function') {
node_util.callbackify(function () {
return _ttl(key);
})(cb);
} else {
return _ttl(key);
}
}
};
};
function handleResponse(cb) {
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return function (err, result) {
if (err) {
return cb && cb(err);
}
if (opts.parse) {
var isMultiple = Array.isArray(result);
if (!isMultiple) {
result = [result];
}
result = result.map(function (_result) {
try {
_result = JSON.parse(_result);
} catch (e) {
return cb && cb(e);
}
return _result;
});
result = isMultiple ? result : result[0];
}
return cb && cb(null, result);
};
function getValue(value) {
return JSON.stringify(value) || '"undefined"';
}
function isObject(object) {
return _typeof(object) === 'object' && !Array.isArray(object) && object !== null;
}
var methods = {
create: function create() {
return redisStore.apply(void 0, arguments);
}
};
module.exports = methods;
exports.redisStore = redisStore;

@@ -5,5 +5,9 @@ {

"description": "Redis store for node-cache-manager",
"version": "2.0.0",
"version": "3.0.0",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"repository": {

@@ -16,25 +20,24 @@ "type": "git",

"test": "jest --forceExit",
"test-cov": "jest --forceExit --coverage && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
"test-cov": "jest --forceExit --coverage",
"build": "rollup -c"
},
"dependencies": {
"redis": "^3.0.2"
"redis": "^4.3.1"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"@babel/runtime": "^7.8.4",
"babel-jest": "^25.1.0",
"cache-manager": "^2.9.0",
"coveralls": "^3.0.9",
"jest": "^25.1.0",
"rollup": "^1.31.0",
"rollup-plugin-babel": "^4.3.3"
"@babel/cli": "^7.19.3",
"@babel/core": "^7.19.3",
"@babel/plugin-transform-runtime": "^7.19.1",
"@babel/preset-env": "^7.19.4",
"@babel/runtime": "^7.19.4",
"@rollup/plugin-babel": "^6.0.0",
"@types/cache-manager": "^4.0.2",
"babel-jest": "^29.2.0",
"cache-manager": "^4.1.0",
"jest": "^29.2.0",
"rollup": "^2.79.1"
},
"engines": {
"node": ">= 8.3"
"node": ">= 16.18.0"
}
}

@@ -1,4 +0,1 @@

[![build status](https://travis-ci.org/dabroek/node-cache-manager-redis-store.svg?branch=master)](https://travis-ci.org/dabroek/node-cache-manager-redis-store)
[![coverage status](https://coveralls.io/repos/github/dabroek/node-cache-manager-redis-store/badge.svg?branch=master)](https://coveralls.io/github/dabroek/node-cache-manager-redis-store?branch=master)
[![dependencies status](https://david-dm.org/dabroek/node-cache-manager-redis-store/status.svg)](https://david-dm.org/dabroek/node-cache-manager-redis-store)
[![npm version](https://badge.fury.io/js/cache-manager-redis-store.svg)](https://badge.fury.io/js/cache-manager-redis-store)

@@ -5,0 +2,0 @@ [![GitHub issues](https://img.shields.io/github/issues/dabroek/node-cache-manager-redis-store.svg)](https://github.com/dabroek/node-cache-manager-redis-store/issues)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc