@azteam/redis-async 1.0.64 → 1.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _RedisAsync = _interopRequireDefault(require("./RedisAsync"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { 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 define(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(); } 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 reset(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 stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(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); } } } }, abrupt: function abrupt(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; } } 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); }, complete: function complete(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 finish(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; } }, "catch": function _catch(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 delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
11
+ 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); } }
12
+ 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); }); }; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ var Provider = /*#__PURE__*/function () {
17
+ function Provider() {
18
+ var _this = this;
19
+ var configs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
20
+ _classCallCheck(this, Provider);
21
+ this.connections = {};
22
+ this.configs = {};
23
+ if (Array.isArray(configs)) {
24
+ configs.map(function (config) {
25
+ _this.configs[config.name] = config;
26
+ return true;
27
+ });
28
+ } else {
29
+ this.configs.main = configs;
30
+ }
31
+ }
32
+ _createClass(Provider, [{
33
+ key: "getConnection",
34
+ value: function getConnection() {
35
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'main';
36
+ if (!this.connections[name]) {
37
+ this.connections[name] = new _RedisAsync["default"](this.configs[name]);
38
+ }
39
+ return this.connections[name];
40
+ }
41
+ }, {
42
+ key: "waitAllConnection",
43
+ value: function () {
44
+ var _waitAllConnection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
45
+ var _this2 = this;
46
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
47
+ while (1) {
48
+ switch (_context.prev = _context.next) {
49
+ case 0:
50
+ _context.next = 2;
51
+ return Promise.all(Object.keys(this.configs).map(function (keyConfig) {
52
+ var connection = _this2.getConnection(keyConfig);
53
+ return connection.waitConnection();
54
+ }));
55
+ case 2:
56
+ case "end":
57
+ return _context.stop();
58
+ }
59
+ }
60
+ }, _callee, this);
61
+ }));
62
+ function waitAllConnection() {
63
+ return _waitAllConnection.apply(this, arguments);
64
+ }
65
+ return waitAllConnection;
66
+ }()
67
+ }]);
68
+ return Provider;
69
+ }();
70
+ var _default = Provider;
71
+ exports["default"] = _default;
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _redis = require("redis");
9
+ var _util = require("@azteam/util");
10
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { 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 define(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(); } 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 reset(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 stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(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); } } } }, abrupt: function abrupt(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; } } 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); }, complete: function complete(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 finish(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; } }, "catch": function _catch(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 delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
11
+ 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); } }
12
+ 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); }); }; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ var RedisAsync = /*#__PURE__*/function () {
17
+ function RedisAsync(config) {
18
+ _classCallCheck(this, RedisAsync);
19
+ this.connected = false;
20
+ this.host = config.host;
21
+ this.port = config.port;
22
+ this.prefix = config.prefix;
23
+ this.connect();
24
+ }
25
+ _createClass(RedisAsync, [{
26
+ key: "waitConnection",
27
+ value: function () {
28
+ var _waitConnection = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
29
+ var n,
30
+ i,
31
+ _args = arguments;
32
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
33
+ while (1) {
34
+ switch (_context.prev = _context.next) {
35
+ case 0:
36
+ n = _args.length > 0 && _args[0] !== undefined ? _args[0] : 10;
37
+ i = 0;
38
+ case 2:
39
+ if (!(!this.connected || i < n)) {
40
+ _context.next = 8;
41
+ break;
42
+ }
43
+ _context.next = 5;
44
+ return (0, _util.timeout)(1000);
45
+ case 5:
46
+ i += 1;
47
+ _context.next = 2;
48
+ break;
49
+ case 8:
50
+ if (this.connected) {
51
+ _context.next = 10;
52
+ break;
53
+ }
54
+ throw new Error('Redis not connected');
55
+ case 10:
56
+ case "end":
57
+ return _context.stop();
58
+ }
59
+ }
60
+ }, _callee, this);
61
+ }));
62
+ function waitConnection() {
63
+ return _waitConnection.apply(this, arguments);
64
+ }
65
+ return waitConnection;
66
+ }()
67
+ }, {
68
+ key: "parsePrefix",
69
+ value: function parsePrefix(name) {
70
+ if (this.prefix) {
71
+ return "".concat(this.prefix, ":").concat(name);
72
+ }
73
+ return name;
74
+ }
75
+ }, {
76
+ key: "connect",
77
+ value: function connect() {
78
+ var _this = this;
79
+ this._alert('connecting', 'Redis connecting...');
80
+ this.client = (0, _redis.createClient)({
81
+ host: this.host,
82
+ port: this.port,
83
+ retry_strategy: function retry_strategy(options) {
84
+ _this.connected = false;
85
+ _this._alert('connect', 'Redis disconnected');
86
+ _this.client.quit();
87
+ }
88
+ });
89
+ this.client.connect();
90
+ this.client.on('connect', function () {
91
+ _this.connected = true;
92
+ _this._alert('connect', 'Redis connected');
93
+ });
94
+ this.client.on('end', function () {
95
+ _this._alert('end', 'Redis end');
96
+ });
97
+ this.client.on('error', function (err) {
98
+ _this._alert('error', "Redis Error".concat(err));
99
+ });
100
+ }
101
+ }, {
102
+ key: "get",
103
+ value: function () {
104
+ var _get = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(key) {
105
+ var defaultValue,
106
+ prefixKey,
107
+ data,
108
+ _args2 = arguments;
109
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
110
+ while (1) {
111
+ switch (_context2.prev = _context2.next) {
112
+ case 0:
113
+ defaultValue = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : null;
114
+ prefixKey = this.parsePrefix(key);
115
+ if (!this.connected) {
116
+ _context2.next = 11;
117
+ break;
118
+ }
119
+ console.log("Redis GET ".concat(prefixKey));
120
+ _context2.next = 6;
121
+ return this.client.get(prefixKey);
122
+ case 6:
123
+ data = _context2.sent;
124
+ if (!data) {
125
+ _context2.next = 9;
126
+ break;
127
+ }
128
+ return _context2.abrupt("return", JSON.parse(data));
129
+ case 9:
130
+ _context2.next = 13;
131
+ break;
132
+ case 11:
133
+ this.connect();
134
+ return _context2.abrupt("return", null);
135
+ case 13:
136
+ return _context2.abrupt("return", defaultValue);
137
+ case 14:
138
+ case "end":
139
+ return _context2.stop();
140
+ }
141
+ }
142
+ }, _callee2, this);
143
+ }));
144
+ function get(_x) {
145
+ return _get.apply(this, arguments);
146
+ }
147
+ return get;
148
+ }()
149
+ }, {
150
+ key: "ttl",
151
+ value: function () {
152
+ var _ttl = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(key) {
153
+ var prefixKey;
154
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
155
+ while (1) {
156
+ switch (_context3.prev = _context3.next) {
157
+ case 0:
158
+ prefixKey = this.parsePrefix(key);
159
+ return _context3.abrupt("return", this.client.ttl(prefixKey));
160
+ case 2:
161
+ case "end":
162
+ return _context3.stop();
163
+ }
164
+ }
165
+ }, _callee3, this);
166
+ }));
167
+ function ttl(_x2) {
168
+ return _ttl.apply(this, arguments);
169
+ }
170
+ return ttl;
171
+ }()
172
+ }, {
173
+ key: "expire",
174
+ value: function () {
175
+ var _expire = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(key) {
176
+ var timeSecond,
177
+ prefixKey,
178
+ _args4 = arguments;
179
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
180
+ while (1) {
181
+ switch (_context4.prev = _context4.next) {
182
+ case 0:
183
+ timeSecond = _args4.length > 1 && _args4[1] !== undefined ? _args4[1] : 86400;
184
+ prefixKey = this.parsePrefix(key);
185
+ this.client.expire(prefixKey, timeSecond);
186
+ case 3:
187
+ case "end":
188
+ return _context4.stop();
189
+ }
190
+ }
191
+ }, _callee4, this);
192
+ }));
193
+ function expire(_x3) {
194
+ return _expire.apply(this, arguments);
195
+ }
196
+ return expire;
197
+ }()
198
+ }, {
199
+ key: "set",
200
+ value: function () {
201
+ var _set = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(key, data) {
202
+ var timeSecond,
203
+ count,
204
+ prefixKey,
205
+ _args5 = arguments;
206
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
207
+ while (1) {
208
+ switch (_context5.prev = _context5.next) {
209
+ case 0:
210
+ timeSecond = _args5.length > 2 && _args5[2] !== undefined ? _args5[2] : 86400;
211
+ count = _args5.length > 3 && _args5[3] !== undefined ? _args5[3] : 0;
212
+ prefixKey = this.parsePrefix(key);
213
+ if (!this.connected) {
214
+ _context5.next = 12;
215
+ break;
216
+ }
217
+ console.log("Redis SET ".concat(prefixKey));
218
+ _context5.next = 7;
219
+ return this.client.set(prefixKey, JSON.stringify(data));
220
+ case 7:
221
+ _context5.next = 9;
222
+ return this.expire(prefixKey, timeSecond);
223
+ case 9:
224
+ return _context5.abrupt("return", true);
225
+ case 12:
226
+ this.connect();
227
+ if (!(count < 5)) {
228
+ _context5.next = 15;
229
+ break;
230
+ }
231
+ return _context5.abrupt("return", this.set(key, data, timeSecond, count + 1));
232
+ case 15:
233
+ return _context5.abrupt("return", false);
234
+ case 16:
235
+ case "end":
236
+ return _context5.stop();
237
+ }
238
+ }
239
+ }, _callee5, this);
240
+ }));
241
+ function set(_x4, _x5) {
242
+ return _set.apply(this, arguments);
243
+ }
244
+ return set;
245
+ }() // async scan(pattern, cursor = 0, count = 1000) {
246
+ // const scanAsync = promisify(this.client.scan).bind(this.client);
247
+ // return await scanAsync(cursor, 'MATCH', pattern, 'COUNT', count);
248
+ // }
249
+ }, {
250
+ key: "remove",
251
+ value: function () {
252
+ var _remove = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(key) {
253
+ var exact,
254
+ count,
255
+ prefixKey,
256
+ regexKey,
257
+ keys,
258
+ _args6 = arguments;
259
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
260
+ while (1) {
261
+ switch (_context6.prev = _context6.next) {
262
+ case 0:
263
+ exact = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : true;
264
+ count = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : 0;
265
+ prefixKey = this.parsePrefix(key);
266
+ if (!this.connected) {
267
+ _context6.next = 19;
268
+ break;
269
+ }
270
+ if (!exact) {
271
+ _context6.next = 10;
272
+ break;
273
+ }
274
+ console.log("Redis REMOVE ".concat(prefixKey));
275
+ _context6.next = 8;
276
+ return this.client.del(prefixKey);
277
+ case 8:
278
+ _context6.next = 17;
279
+ break;
280
+ case 10:
281
+ regexKey = "*".concat(prefixKey, "*");
282
+ _context6.next = 13;
283
+ return this.client.keys(regexKey);
284
+ case 13:
285
+ keys = _context6.sent;
286
+ if (!(keys.length > 0)) {
287
+ _context6.next = 17;
288
+ break;
289
+ }
290
+ console.log("Redis REMOVE keys", keys);
291
+ return _context6.abrupt("return", this.client.del(keys));
292
+ case 17:
293
+ _context6.next = 23;
294
+ break;
295
+ case 19:
296
+ this.connect();
297
+ if (!(count < 5)) {
298
+ _context6.next = 22;
299
+ break;
300
+ }
301
+ return _context6.abrupt("return", this.remove(key, exact, count + 1));
302
+ case 22:
303
+ return _context6.abrupt("return", false);
304
+ case 23:
305
+ return _context6.abrupt("return", false);
306
+ case 24:
307
+ case "end":
308
+ return _context6.stop();
309
+ }
310
+ }
311
+ }, _callee6, this);
312
+ }));
313
+ function remove(_x6) {
314
+ return _remove.apply(this, arguments);
315
+ }
316
+ return remove;
317
+ }()
318
+ }, {
319
+ key: "setAlertCallback",
320
+ value: function setAlertCallback(callback) {
321
+ this.alertCallback = callback;
322
+ }
323
+ }, {
324
+ key: "_alert",
325
+ value: function _alert(status, msg) {
326
+ if (typeof this.alertCallback === 'function') {
327
+ this.alertCallback(status, msg);
328
+ } else {
329
+ console.error(status, msg);
330
+ }
331
+ }
332
+ }]);
333
+ return RedisAsync;
334
+ }();
335
+ var _default = RedisAsync;
336
+ exports["default"] = _default;
package/lib/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "RedisAsync", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _RedisAsync["default"];
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "RedisProvider", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _Provider["default"];
16
+ }
17
+ });
18
+ var _Provider = _interopRequireDefault(require("./Provider"));
19
+ var _RedisAsync = _interopRequireDefault(require("./RedisAsync"));
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@azteam/redis-async",
3
- "version": "1.0.64",
3
+ "version": "1.0.66",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./src/index.js",
7
7
  "scripts": {
8
- "build": "babel src -d lib",
9
- "prepublish": "npm run build"
8
+ "build": "babel src -d lib"
10
9
  },
11
10
  "keywords": [
12
11
  "toda",
@@ -17,7 +16,7 @@
17
16
  "author": "toda <sp.azsolution.net@gmail.com>",
18
17
  "license": "MIT",
19
18
  "dependencies": {
20
- "@azteam/util": "1.0.15",
19
+ "@azteam/util": "1.0.16",
21
20
  "redis": "4.0.6"
22
21
  }
23
22
  }