UNPKG

ucc-utils

Version:
1 lines 4.07 kB
"use strict";function t(t,e,n,r,i,u,o){try{var c=t[u](o);var s=c.value}catch(t){n(t);return}if(c.done){e(s)}else{Promise.resolve(s).then(r,i)}}function e(e){return function(){var n=this,r=arguments;return new Promise(function(i,u){var o=e.apply(n,r);function c(e){t(o,i,u,c,s,"next",e)}function s(e){t(o,i,u,c,s,"throw",e)}c(undefined)})}}function n(t,e){if(!(t instanceof e)){throw new TypeError("Cannot call a class as a function")}}function r(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||false;r.configurable=true;if("value"in r)r.writable=true;Object.defineProperty(t,r.key,r)}}function i(t,e,n){if(e)r(t.prototype,e);if(n)r(t,n);return t}function u(t){"@swc/helpers - typeof";return t&&typeof Symbol!=="undefined"&&t.constructor===Symbol?"symbol":typeof t}function o(t,e){var n,r,i,u,o={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]};return u={next:c(0),"throw":c(1),"return":c(2)},typeof Symbol==="function"&&(u[Symbol.iterator]=function(){return this}),u;function c(t){return function(e){return s([t,e])}}function s(u){if(n)throw new TypeError("Generator is already executing.");while(o)try{if(n=1,r&&(i=u[0]&2?r["return"]:u[0]?r["throw"]||((i=r["return"])&&i.call(r),0):r.next)&&!(i=i.call(r,u[1])).done)return i;if(r=0,i)u=[u[0]&2,i.value];switch(u[0]){case 0:case 1:i=u;break;case 4:o.label++;return{value:u[1],done:false};case 5:o.label++;r=u[1];u=[0];continue;case 7:u=o.ops.pop();o.trys.pop();continue;default:if(!(i=o.trys,i=i.length>0&&i[i.length-1])&&(u[0]===6||u[0]===2)){o=0;continue}if(u[0]===3&&(!i||u[1]>i[0]&&u[1]<i[3])){o.label=u[1];break}if(u[0]===6&&o.label<i[1]){o.label=i[1];i=u;break}if(i&&o.label<i[2]){o.label=i[2];o.ops.push(u);break}if(i[2])o.ops.pop();o.trys.pop();continue}u=e.call(t,o)}catch(t){u=[6,t];r=0}finally{n=i=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}}var c=require("redis");function s(t){return t&&t.__esModule?t:{default:t}}var a=s(c);var l=/*#__PURE__*/function(){function t(e){n(this,t);this.host="localhost";this.port=6379;this.setOptions(e),this._init()}i(t,[{key:"_init",value:function t(){this.client=a.default.createClient({url:"redis://".concat(this.host,":").concat(this.port)})}},{key:"set",value:function t(t,n){var r=this;return e(function(){var i;return o(this,function(c){switch(c.label){case 0:if(!(typeof t=="string"))return[3,2];return[4,r._toTryCatch(r.client.SET,t,n)];case 1:return[2,c.sent()];case 2:if((typeof t==="undefined"?"undefined":u(t))=="object"&&!Array.isArray(t)&&!Buffer.isBuffer(t)){i=[];return[2,(Object.keys(t).forEach(/*#__PURE__*/function(){var n=e(function(e){var n;return o(this,function(u){switch(u.label){case 0:n=i.push;return[4,r._toTryCatch(r.client.SET,e,t[e])];case 1:return[2,n.apply(i,[u.sent()])]}})});return function(t){return n.apply(this,arguments)}}()),i)]}return[2]}})})()}},{key:"setOptions",value:function t(t){var e=t.host,n=t.port;return e&&(this.host=e),n&&(this.port=n),this}},{key:"connect",value:function t(){var t=this;return e(function(){return o(this,function(e){switch(e.label){case 0:return[4,t._toTryCatch(t.client.connect)];case 1:return[2,e.sent()]}})})()}},{key:"disconnect",value:function t(){var t=this;return e(function(){return o(this,function(e){switch(e.label){case 0:return[4,t._toTryCatch(t.client.disconnect)];case 1:return[2,e.sent()]}})})()}},{key:"recreate",value:function t(t){return this.setOptions(t||{}),this._init(),this}},{key:"quit",value:function t(){var t=this;return e(function(){var e;return o(this,function(n){switch(n.label){case 0:return[4,t._toTryCatch((e=t.client)===null||e===void 0?void 0:e.QUIT)];case 1:return[2,n.sent()]}})})()}},{key:"_toTryCatch",value:function t(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),i=1;i<n;i++){r[i-1]=arguments[i]}return e(function(){var e,n;return o(this,function(i){switch(i.label){case 0:i.trys.push([0,2,,3]);e={status:!0};return[4,t(r)];case 1:return[2,(e.result=i.sent(),e)];case 2:n=i.sent();return[2,(console.log(n),{status:!1,error:n})];case 3:return[2]}})})()}}]);return t}();exports.Redis=l;