redis-smq-common 2.0.0 → 3.0.0-rc.1
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.
- package/CHANGELOG.md +36 -3
- package/README.md +7 -1
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +464 -0
- package/dist/index.d.ts +464 -12
- package/dist/index.js +3 -27
- package/dist/lua/extend-lock.lua +16 -0
- package/dist/{src/redis-client/lua → lua}/lpoprpush.lua +9 -0
- package/dist/lua/release-lock.lua +15 -0
- package/dist/lua/zpoprpush.lua +22 -0
- package/docs/README.md +13 -0
- package/package.json +22 -30
- package/.codecov.yml +0 -5
- package/dist/src/async/async.d.ts +0 -7
- package/dist/src/async/async.js +0 -80
- package/dist/src/errors/argument.error.d.ts +0 -3
- package/dist/src/errors/argument.error.js +0 -8
- package/dist/src/errors/empty-callback-reply.error.d.ts +0 -4
- package/dist/src/errors/empty-callback-reply.error.js +0 -11
- package/dist/src/errors/generic.error.d.ts +0 -3
- package/dist/src/errors/generic.error.js +0 -8
- package/dist/src/errors/index.d.ts +0 -14
- package/dist/src/errors/index.js +0 -18
- package/dist/src/errors/invalid-callback-reply.error.d.ts +0 -4
- package/dist/src/errors/invalid-callback-reply.error.js +0 -11
- package/dist/src/errors/panic.error.d.ts +0 -3
- package/dist/src/errors/panic.error.js +0 -8
- package/dist/src/errors/redis-smq.error.d.ts +0 -3
- package/dist/src/errors/redis-smq.error.js +0 -10
- package/dist/src/events/events.d.ts +0 -8
- package/dist/src/events/events.js +0 -12
- package/dist/src/lock-manager/errors/lock-manager-abort.error.d.ts +0 -4
- package/dist/src/lock-manager/errors/lock-manager-abort.error.js +0 -11
- package/dist/src/lock-manager/errors/lock-manager-acquire.error.d.ts +0 -4
- package/dist/src/lock-manager/errors/lock-manager-acquire.error.js +0 -11
- package/dist/src/lock-manager/errors/lock-manager-extend.error.d.ts +0 -4
- package/dist/src/lock-manager/errors/lock-manager-extend.error.js +0 -11
- package/dist/src/lock-manager/errors/lock-manager-method-not-allowed.error.d.ts +0 -4
- package/dist/src/lock-manager/errors/lock-manager-method-not-allowed.error.js +0 -11
- package/dist/src/lock-manager/errors/lock-manager-not-acquired.error.d.ts +0 -4
- package/dist/src/lock-manager/errors/lock-manager-not-acquired.error.js +0 -11
- package/dist/src/lock-manager/errors/lock-manager-not-released.error.d.ts +0 -4
- package/dist/src/lock-manager/errors/lock-manager-not-released.error.js +0 -11
- package/dist/src/lock-manager/errors/lock-manager.error.d.ts +0 -3
- package/dist/src/lock-manager/errors/lock-manager.error.js +0 -8
- package/dist/src/lock-manager/lock-manager.d.ts +0 -41
- package/dist/src/lock-manager/lock-manager.js +0 -211
- package/dist/src/lock-manager/redis-client/lua/extend-lock.lua +0 -7
- package/dist/src/lock-manager/redis-client/lua/release-lock.lua +0 -6
- package/dist/src/logger/logger.d.ts +0 -12
- package/dist/src/logger/logger.error.d.ts +0 -3
- package/dist/src/logger/logger.error.js +0 -8
- package/dist/src/logger/logger.js +0 -58
- package/dist/src/power-manager/power-manager.d.ts +0 -21
- package/dist/src/power-manager/power-manager.error.d.ts +0 -3
- package/dist/src/power-manager/power-manager.error.js +0 -8
- package/dist/src/power-manager/power-manager.js +0 -68
- package/dist/src/redis-client/clients/ioredis-client-multi.d.ts +0 -24
- package/dist/src/redis-client/clients/ioredis-client-multi.js +0 -108
- package/dist/src/redis-client/clients/ioredis-client.d.ts +0 -61
- package/dist/src/redis-client/clients/ioredis-client.js +0 -217
- package/dist/src/redis-client/clients/node-redis-v3-client-multi.d.ts +0 -24
- package/dist/src/redis-client/clients/node-redis-v3-client-multi.js +0 -89
- package/dist/src/redis-client/clients/node-redis-v3-client.d.ts +0 -61
- package/dist/src/redis-client/clients/node-redis-v3-client.js +0 -249
- package/dist/src/redis-client/clients/node-redis-v4-client-multi.d.ts +0 -23
- package/dist/src/redis-client/clients/node-redis-v4-client-multi.js +0 -91
- package/dist/src/redis-client/clients/node-redis-v4-client.d.ts +0 -61
- package/dist/src/redis-client/clients/node-redis-v4-client.js +0 -324
- package/dist/src/redis-client/create-client-instance.d.ts +0 -3
- package/dist/src/redis-client/create-client-instance.js +0 -33
- package/dist/src/redis-client/errors/redis-client.error.d.ts +0 -3
- package/dist/src/redis-client/errors/redis-client.error.js +0 -8
- package/dist/src/redis-client/errors/watched-keys-changed.error.d.ts +0 -4
- package/dist/src/redis-client/errors/watched-keys-changed.error.js +0 -11
- package/dist/src/redis-client/lua/lpoprpushextra.lua +0 -20
- package/dist/src/redis-client/lua/zpophgetrpush.lua +0 -15
- package/dist/src/redis-client/lua-scripts.d.ts +0 -13
- package/dist/src/redis-client/lua-scripts.js +0 -57
- package/dist/src/redis-client/redis-client.d.ts +0 -76
- package/dist/src/redis-client/redis-client.js +0 -110
- package/dist/src/ticker/ticker.d.ts +0 -23
- package/dist/src/ticker/ticker.error.d.ts +0 -3
- package/dist/src/ticker/ticker.error.js +0 -8
- package/dist/src/ticker/ticker.js +0 -121
- package/dist/src/worker/worker-error.d.ts +0 -3
- package/dist/src/worker/worker-error.js +0 -8
- package/dist/src/worker/worker-runner/worker-pool.d.ts +0 -8
- package/dist/src/worker/worker-runner/worker-pool.js +0 -31
- package/dist/src/worker/worker-runner/worker-runner.d.ts +0 -22
- package/dist/src/worker/worker-runner/worker-runner.js +0 -66
- package/dist/src/worker/worker.d.ts +0 -13
- package/dist/src/worker/worker.js +0 -63
- package/dist/types/index.d.ts +0 -75
- package/dist/types/index.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
# CHANGELOG
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
## [3.0.0-rc.1](https://github.com/weyoss/redis-smq-common/compare/v2.0.0...v3.0.0-rc.1) (2023-11-19)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* support cjs/esm modules, refactor codebase, improve typings
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* **redis-client:** add hscan support ([7672617](https://github.com/weyoss/redis-smq-common/commit/7672617c5438b677420f24591cc849082084602f))
|
|
13
|
+
* support cjs/esm modules, refactor codebase, improve typings ([3da25b9](https://github.com/weyoss/redis-smq-common/commit/3da25b91dfce72051df0e409de00b1ef40e91d1c))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* **NodeRedisV4Client:** fix zrevrange() error for Redis v2.8 ([f0d9e25](https://github.com/weyoss/redis-smq-common/commit/f0d9e2563821c161aba92b1518249b89da448b76))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Misc
|
|
22
|
+
|
|
23
|
+
* fix broken links ([6b2e9cf](https://github.com/weyoss/redis-smq-common/commit/6b2e9cf222eff79bf9355d46d9677d378347b740))
|
|
24
|
+
* improve documentation, add API reference, clean up ([53169a1](https://github.com/weyoss/redis-smq-common/commit/53169a1b459a7f0db9907bba18f900dc179cc366))
|
|
25
|
+
* **logger:** fix getLogger() tests when called with the 2nd param ([df43847](https://github.com/weyoss/redis-smq-common/commit/df438470cdc306311cc70aca72e19f3b1dcd2c46))
|
|
26
|
+
* **redis-client:** fix 'ERR unknown command HSCAN' error ([70a5c98](https://github.com/weyoss/redis-smq-common/commit/70a5c98ae5281b0f0a04ab6f2414da620cad2ae7))
|
|
27
|
+
* **redis-client:** increase code coverage ([34fccba](https://github.com/weyoss/redis-smq-common/commit/34fccba189078cb56b1c86b83662f9d927a28182))
|
|
28
|
+
* **redis-client:** test hscan support ([939a0ad](https://github.com/weyoss/redis-smq-common/commit/939a0ad1eb417e3d5e5607306ad9d172285c4c5d))
|
|
29
|
+
* **redis-client:** Use count param for sscan ([8705086](https://github.com/weyoss/redis-smq-common/commit/87050869cf580e778bc9a5e8ede19e02884f8a87))
|
|
30
|
+
* update .gitignore ([6fbc308](https://github.com/weyoss/redis-smq-common/commit/6fbc3087b74395ac3558e310bf58c378184608e3))
|
|
31
|
+
* update CHANGELOG.md template ([aae81f3](https://github.com/weyoss/redis-smq-common/commit/aae81f376c3404a13a8647774d26175eff58b39d))
|
|
32
|
+
* update minimal supported versions for nodejs and redis ([4a31852](https://github.com/weyoss/redis-smq-common/commit/4a31852a889cffb82eac2b3454dac323a39da79a))
|
|
33
|
+
* update package description ([776a240](https://github.com/weyoss/redis-smq-common/commit/776a24029a6d79c132d5b861139926c6ffc7288b))
|
|
34
|
+
* update tests and fix various errors ([c915fb2](https://github.com/weyoss/redis-smq-common/commit/c915fb240cf8f8781f98bd6aa77023b26e1a0fde))
|
|
35
|
+
|
|
36
|
+
## 2.0.0 (2023-03-25)
|
|
4
37
|
|
|
5
38
|
* feat(redis-client): support offset and count for zrangebyscore() (2ec00e0)
|
|
6
39
|
|
|
@@ -107,4 +140,4 @@
|
|
|
107
140
|
|
|
108
141
|
* Update package keywords and description
|
|
109
142
|
* Use codecov instead of coveralls
|
|
110
|
-
* Initial commit, migrate common components from redis-smq
|
|
143
|
+
* Initial commit, migrate common components from redis-smq
|
package/README.md
CHANGED
|
@@ -12,7 +12,13 @@
|
|
|
12
12
|
<a href="https://codecov.io/github/weyoss/redis-smq-common?branch=master" rel="nofollow"><img src="https://img.shields.io/codecov/c/github/weyoss/redis-smq-common" alt="Coverage Status" /></a>
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
|
-
[RedisSMQ](https://github.com/weyoss/redis-smq)
|
|
15
|
+
RedisSMQ Common Library provides many components that are mainly used by [RedisSMQ](https://github.com/weyoss/redis-smq) and [RedisSMQ Monitor](https://github.com/weyoss/redis-smq-monitor).
|
|
16
|
+
|
|
17
|
+
This library is included as part of RedisSMQ and not intended to be installed separately as a stand-alone package.
|
|
18
|
+
|
|
19
|
+
## Documentation
|
|
20
|
+
|
|
21
|
+
See [Docs](docs/README.md) for more details.
|
|
16
22
|
|
|
17
23
|
## License
|
|
18
24
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var xt=Object.create;var D=Object.defineProperty,Tt=Object.defineProperties,Rt=Object.getOwnPropertyDescriptor,yt=Object.getOwnPropertyDescriptors,Et=Object.getOwnPropertyNames,nt=Object.getOwnPropertySymbols,St=Object.getPrototypeOf,ot=Object.prototype.hasOwnProperty,Ot=Object.prototype.propertyIsEnumerable;var st=(o,r,t)=>r in o?D(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,V=(o,r)=>{for(var t in r||(r={}))ot.call(r,t)&&st(o,t,r[t]);if(nt)for(var t of nt(r))Ot.call(r,t)&&st(o,t,r[t]);return o},lt=(o,r)=>Tt(o,yt(r));var Nt=(o,r)=>{for(var t in r)D(o,t,{get:r[t],enumerable:!0})},at=(o,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of Et(r))!ot.call(o,e)&&e!==t&&D(o,e,{get:()=>r[e],enumerable:!(i=Rt(r,e))||i.enumerable});return o};var j=(o,r,t)=>(t=o!=null?xt(St(o)):{},at(r||!o||!o.__esModule?D(t,"default",{value:o,enumerable:!0}):t,o)),Lt=o=>at(D({},"__esModule",{value:!0}),o);var Xt={};Nt(Xt,{CallbackEmptyReplyError:()=>b,CallbackInvalidReplyError:()=>G,ERedisConfigClient:()=>Y,Lock:()=>F,LockAbortError:()=>x,LockAcquireError:()=>y,LockError:()=>h,LockExtendError:()=>L,LockMethodNotAllowedError:()=>M,LockNotAcquiredError:()=>A,LockNotReleasedError:()=>U,LoggerError:()=>P,PanicError:()=>R,PowerSwitch:()=>I,PowerSwitchError:()=>T,RedisClient:()=>k,RedisClientError:()=>u,RedisSMQError:()=>g,Ticker:()=>S,TickerError:()=>N,WatchedKeysChangedError:()=>f,Worker:()=>X,WorkerError:()=>E,WorkerPool:()=>W,WorkerRunner:()=>q,async:()=>v,events:()=>p,logger:()=>pt,redis:()=>It});module.exports=Lt(Xt);var Y=(i=>(i.REDIS="redis",i.IOREDIS="ioredis",i.REDIS_V4="redis_v4",i))(Y||{});var g=class extends Error{constructor(r){super(r)}get name(){return this.constructor.name}};var b=class extends g{constructor(){super("Expected a non-empty reply")}};var G=class extends g{constructor(){super("Invalid reply type")}};var R=class extends g{};var P=class extends g{};var N=class extends g{};var h=class extends g{};var x=class extends h{constructor(r="releaseLock() may have been called. Abandoning."){super(r)}};var y=class extends h{constructor(r="Could not acquire a lock"){super(r)}};var L=class extends h{constructor(r="Acquired lock could not be extended"){super(r)}};var M=class extends h{constructor(r="This method can not be used when autoExtend is enabled"){super(r)}};var A=class extends h{constructor(r="Can not extend a lock which has not been yet acquired. Maybe a pending operation is in progress."){super(r)}};var U=class extends h{constructor(r="A lock has been already obtained but not yet released or maybe a pending operation is in progress."){super(r)}};var u=class extends g{};var f=class extends u{constructor(r="One (or more) of the watched keys has been changed"){super(r)}};var E=class extends R{};var T=class extends g{};var ut=require("uuid");var et=j(require("fs"),1),rt=require("path");var gt=require("events");var ct=(o,r,t)=>{if(o.length){let i=0,e=()=>{r(o[i],i,n=>{i+=1,n||i>=o.length?t(n):setTimeout(()=>e(),0)})};e()}else t()},dt=(o,r,t)=>{let i=Object.keys(o);if(i.length){let e=0,n=()=>{let s=i[e];r(o[s],s,l=>{e+=1,l||e>=i.length?t(l):setTimeout(()=>n(),0)})};n()}else t()},Mt=(o,r,t)=>{Array.isArray(o)?ct(o,r,t):dt(o,r,t)},At=(o,r)=>{if(o.length){let t=0,i=(e,...n)=>{t+=1,e?r(e):t<o.length?setTimeout(()=>{n.length?o[t](...n,i):o[t](i)},0):n.length?r(null,n[0]):r()};o[t](i)}else r()},v={each:Mt,eachIn:dt,eachOf:ct,waterfall:At};var tt=j(require("fs"),1),it=require("path");var z=class z{constructor(){this.isLoaded=!1;this.scripts=new Map,this.addScript("ZPOPRPUSH",tt.default.readFileSync((0,it.resolve)(__dirname,"./lua/zpoprpush.lua")).toString()),this.addScript("LPOPRPUSH",tt.default.readFileSync((0,it.resolve)(__dirname,"./lua/lpoprpush.lua")).toString())}hasScript(r){return this.scripts.has(r)}addScript(r,t){return this.hasScript(r)?!1:(this.scripts.set(r,{content:t}),this.isLoaded=!1,!0)}loadScripts(r,t){if(this.isLoaded)t();else{let i=[];this.scripts.forEach(e=>i.push(n=>{e.id?n():r.loadScript(e.content,(s,l)=>{s?n(s):l?(e.id=l,n()):n(new b)})})),v.waterfall(i,e=>{e?t(e):(this.isLoaded=!0,t())})}}getScriptId(r){var i;let{id:t}=(i=this.scripts.get(r))!=null?i:{};if(!t)throw new u(`ID of script [${r}] is missing`);return t}static getInstance(){return z.instance||(z.instance=new z),z.instance}};z.instance=null;var H=z;var zt=[2,8,0],C=class C extends gt.EventEmitter{constructor(){super(...arguments);this.connectionClosed=!0}validateRedisVersion(t,i=0,e=0){if(!C.redisServerVersion)throw new u("UNKNOWN_REDIS_SERVER_VERSION");return C.redisServerVersion[0]>t||C.redisServerVersion[0]===t&&C.redisServerVersion[1]>=i&&C.redisServerVersion[2]>=e}validateRedisServerSupport(t){let i=e=>{let[n,s,l]=zt;this.validateRedisVersion(n,s,l)?e():e(new u("UNSUPPORTED_REDIS_SERVER_VERSION"))};C.redisServerVersion?i(t):this.updateServerVersion(e=>{e?t(e):i(t)})}sscanAll(t,i,e){let n=new Set,s=l=>{this.sscan(t,l,i,(a,c)=>{a?e(a):c?(c.items.forEach(d=>n.add(d)),c.cursor==="0"?e(null,[...n]):s(c.cursor)):e(new b)})};s("0")}hscanAll(t,i,e){let n={},s=l=>{this.hscan(t,l,i,(a,c)=>{a?e(a):c?(Object.assign(n,c.result),c.cursor==="0"?e(null,n):s(c.cursor)):e(new b)})};s("0")}zpoprpush(t,i,e){this.runScript("ZPOPRPUSH",[t,i],[],(n,s)=>{n?e(n):e(null,typeof s=="string"?s:null)})}lpoprpush(t,i,e){this.validateRedisVersion(6,2)?this.lmove(t,i,"LEFT","RIGHT",e):this.runScript("LPOPRPUSH",[t,i],[],(n,s)=>{n?e(n):e(null,typeof s=="string"?s:null)})}updateServerVersion(t){C.redisServerVersion?t():this.getInfo((i,e)=>{i?t(i):e?(C.redisServerVersion=e.split(`\r
|
|
2
|
+
`)[1].split(":")[1].split(".").map(n=>Number(n)),t()):t(new b)})}loadScripts(t){H.getInstance().loadScripts(this,t)}runScript(t,i,e,n){let s=H.getInstance().getScriptId(t);this.evalsha(s,[i.length,...i,...e],(l,a)=>{l?n(l):n(null,a)})}static addScript(t,i){if(!H.getInstance().addScript(t,i))throw new u(`A script with name [${t}] already exists`)}};C.redisServerVersion=null;var k=C;k.addScript("RELEASE_LOCK",et.default.readFileSync((0,rt.resolve)(__dirname,"./lua/release-lock.lua")).toString());k.addScript("EXTEND_LOCK",et.default.readFileSync((0,rt.resolve)(__dirname,"./lua/extend-lock.lua")).toString());var F=class{constructor(r,t,i,e=!1,n=!1,s=!0){this.status=0;this.lockingTimer=null;this.autoExtendTimer=null;this.throwExceptions=!0;this.lockKey=t,this.ttl=i,this.retryOnFail=e,this.lockId=(0,ut.v4)(),this.redisClient=r,this.autoExtend=n,this.throwExceptions=s}resetTimers(){this.lockingTimer&&(clearTimeout(this.lockingTimer),this.lockingTimer=null),this.autoExtendTimer&&(clearTimeout(this.autoExtendTimer),this.autoExtendTimer=null)}setUnlocked(){this.status=0}setLocked(){this.status=2}setExtended(){this.status=5}extend(r){this.isLocked()?(this.status=4,this.redisClient.runScript("EXTEND_LOCK",[this.lockKey],[this.lockId,this.ttl],(t,i)=>{t?r(t):this.status===4?i?(this.setExtended(),r()):(this.setUnlocked(),r(new L)):r(new x)})):r(new A)}runAutoExtendTimer(){let r=Math.ceil(this.ttl/2);this.autoExtendTimer=setTimeout(()=>this.extend(t=>{if(!t)this.runAutoExtendTimer();else if(this.throwExceptions&&!(t instanceof x))throw t}),r)}acquireLock(r){if(!this.isReleased())r(new U);else{this.status=1;let t=()=>{this.status===1?this.redisClient.set(this.lockKey,this.lockId,{expire:{mode:"PX",value:this.ttl},exists:"NX"},(i,e)=>{i?r(i):this.status===1?e?(this.setLocked(),this.autoExtend&&this.runAutoExtendTimer(),r()):this.retryOnFail?this.lockingTimer=setTimeout(t,1e3):(this.setUnlocked(),r(new y)):r(new x)}):r(new x)};t()}}extendLock(r){this.autoExtend?r(new M):this.extend(r)}releaseLock(r){this.status===0?r():this.isLocked()?(this.resetTimers(),this.status=3,this.redisClient.runScript("RELEASE_LOCK",[this.lockKey],[this.lockId],i=>{i?r(i):(this.setUnlocked(),r())})):r(new A)}acquireOrExtend(r){if(this.autoExtend)r(new M);else{let t=()=>{this.acquireLock(i=>{i?r(i):r(null,2)})};this.isLocked()?this.extend(i=>{i?i instanceof L?t():r(i):r(null,5)}):t()}}isLocked(){return this.status===2||this.status===5}isReleased(){return this.status===0}getId(){return this.lockId}};var I=class{constructor(r=!0){this.isPowered=!1;this.pendingState=null;this.throwExceptionOnError=r}switch(r){if(this.pendingState!==null){if(this.throwExceptionOnError)throw new T("Can not switch state while another state transition is in progress.");return!1}if(r===this.isPowered){if(this.throwExceptionOnError)throw new T("Can not switch to the same current state.");return!1}return this.pendingState=r,!0}isUp(){return this.isPowered}isDown(){return!this.isPowered}isGoingUp(){return this.pendingState===!0}isGoingDown(){return this.pendingState===!1}isRunning(){return this.isUp()&&this.pendingState===null}goingUp(){return this.switch(!0)}goingDown(){return this.switch(!1)}commit(){if(this.pendingState===null)throw new T("Expected a pending state");this.isPowered=this.pendingState,this.pendingState=null}rollback(){if(this.pendingState===null)throw new T("Expected a pending state");this.pendingState=null}};var ht=require("events");var p={GOING_UP:"going_up",UP:"up",GOING_DOWN:"going_down",DOWN:"down",ERROR:"error",TICK:"tick"};var S=class extends ht.EventEmitter{constructor(t=()=>{},i=1e3){super();this.powerManager=new I;this.onNextTickFn=null;this.timeout=null;this.interval=null;this.shutdownTimeout=null;this.aborted=!1;this.onTickFn=t,this.time=i,this.powerManager.goingUp()}shutdown(){this.shutdownTimeout&&clearTimeout(this.shutdownTimeout),this.powerManager.commit(),this.emit(p.DOWN)}onTick(){var t;if(this.powerManager.isGoingDown())this.shutdown();else if(this.powerManager.isRunning()){let i=(t=this.onNextTickFn)!=null?t:this.onTickFn;this.onNextTickFn=null,i()}else this.emit(p.ERROR,new R("Unexpected call"))}abort(){this.aborted||(this.aborted=!0,this.powerManager.isGoingDown()?this.shutdown():this.quit())}quit(){this.powerManager.isGoingUp()?(this.powerManager.rollback(),this.emit(p.DOWN)):this.aborted&&this.powerManager.isDown()?this.emit(p.DOWN):(this.powerManager.goingDown(),this.timeout?(clearTimeout(this.timeout),this.shutdown()):this.interval?(clearInterval(this.interval),this.shutdown()):this.aborted?this.shutdown():this.shutdownTimeout=setTimeout(()=>{this.powerManager.isGoingDown()&&this.shutdown()},6e4))}isTicking(){return!!(this.timeout||this.interval)}nextTick(){if(this.isTicking())throw new N("A timer is already running");this.powerManager.isGoingDown()?this.shutdown():(this.powerManager.isGoingUp()&&this.powerManager.commit(),this.powerManager.isRunning()&&(this.timeout=setTimeout(()=>{this.timeout=null,this.onTick()},this.time)))}nextTickFn(t){this.onNextTickFn=t,this.nextTick()}runTimer(){if(this.isTicking())throw new N("A timer is already running");this.powerManager.isGoingUp()&&this.powerManager.commit(),this.powerManager.isRunning()&&(this.interval=setInterval(()=>this.onTick(),this.time))}};var X=class{constructor(r,t=1e3){this.ticker=null;this.powerManager=null;this.getTicker=()=>{if(!this.ticker)throw new E("Expected an instance of Ticker");return this.ticker};this.onTick=()=>{this.work(r=>{if(r)throw r;this.getTicker().nextTick()})};this.run=()=>{if(this.managed)throw new E("You can not run a managed worker");let r=this.getPowerManager();r.goingUp(),this.getTicker().nextTick(),r.commit()};this.quit=r=>{if(this.managed)r();else{let t=this.getPowerManager();t.goingDown();let i=this.getTicker();i.on(p.DOWN,()=>{t.commit(),r()}),i.quit()}};this.managed=r,r||(this.ticker=new S(this.onTick,t),this.powerManager=new I)}getPowerManager(){if(!this.powerManager)throw new E("Expected an instance of PowerSwitch");return this.powerManager}};var mt=require("events");var q=class extends mt.EventEmitter{constructor(t,i,e,n){super();this.onTick=()=>{v.waterfall([t=>{this.lock.acquireOrExtend((i,e)=>{e===2&&this.logger.info(`Workers are exclusively running from this instance (Lock ID ${this.lock.getId()}).`),t(i)})},t=>{this.workerPool.work(t)}],t=>{!t||t instanceof y?this.ticker.nextTick():this.emit(p.ERROR,t)})};this.clearWorkerPool=t=>{this.workerPool.clear(t)};this.stopTicker=t=>{this.ticker.once(p.DOWN,t),this.ticker.quit()};this.releaseLock=t=>{this.lock.releaseLock(t)};this.run=()=>{this.emit(p.UP),this.ticker.nextTick()};this.quit=t=>{v.waterfall([this.stopTicker,this.clearWorkerPool,this.releaseLock],()=>{this.emit(p.DOWN),t()})};this.powerManager=new I,this.redisClient=t,this.logger=n,this.lock=new F(t,i,6e4),this.ticker=new S(this.onTick),this.workerPool=e}addWorker(t){this.workerPool.add(t)}};var W=class{constructor(){this.pool=[];this.work=r=>{if(this.pool.length){let t=this.pool.map(i=>e=>i.work(e));v.waterfall(t,r)}else r()};this.add=r=>(this.pool.push(r),this.pool.length);this.clear=r=>{v.each(this.pool,(t,i,e)=>{t.quit(e)},()=>{this.pool=[],r()})}}};var bt=require("bunyan");var _=()=>{},Pt={debug:_,warn:_,info:_,error:_},w=null;function Ut(){w=null}function Ht(o){if(w)throw new P("Logger has been already initialized.");w=o}function Ft(o,r){var t;if(!o.enabled)return Pt;if(w||(w=(0,bt.createLogger)(lt(V({},(t=o.options)!=null?t:{}),{name:"redis-smq"}))),r){let i=(e,n)=>(s,...l)=>{let a=typeof s=="string"?`${r} | ${s}`:s;return n[e](a,...l)};return{info:i("info",w),warn:i("warn",w),debug:i("debug",w),error:i("error",w)}}return w}var pt={getLogger:Ft,setLogger:Ht,destroy:Ut};var kt=require("redis");var K=class{constructor(r){this.multi=r.multi()}lrem(r,t,i){return this.multi.lrem(r,t,i),this}lpop(r){return this.multi.lpop(r),this}lpush(r,t){return this.multi.lpush(r,t),this}ltrim(r,t,i){return this.multi.ltrim(r,t,i),this}rpop(r){return this.multi.rpop(r),this}rpush(r,t){return this.multi.rpush(r,t),this}zadd(r,t,i){return this.multi.zadd(r,t,i),this}zrem(r,t){return this.multi.zrem(r,t),this}sadd(r,t){return this.multi.sadd(r,t),this}srem(r,t){return this.multi.srem(r,t),this}hset(r,t,i){return this.multi.hset(r,t,String(i)),this}hdel(r,t){return this.multi.hdel(r,t),this}hincrby(r,t,i){return this.multi.hincrby(r,t,i),this}pexpire(r,t){return this.multi.pexpire(r,t),this}expire(r,t){return this.multi.expire(r,t),this}rpoplpush(r,t){return this.multi.rpoplpush(r,t),this}del(r){return this.multi.del(r),this}exec(r){this.multi.exec((t,i)=>{t?r(t):i?r(null,i):r(new f)})}};var Dt=function(o){return o?this.flush_and_error({message:"Connection forcefully ended and command aborted.",code:"NR_CLOSED"}):arguments.length===0&&this.warn(`Using .end() without the flush parameter is deprecated and throws from v.3.0.0 on.
|
|
3
|
+
Please check the doku (https://github.com/NodeRedis/node_redis) and explictly use flush.`),this.retry_timer&&(clearTimeout(this.retry_timer),this.retry_timer=null),this.stream.removeAllListeners(),this.stream.once("close",()=>{this.emit("end"),this.emitted_end=!0}),this.stream.on("error",()=>{}),this.connected=!1,this.ready=!1,this.closing=!0,this.stream.destroySoon()},Q=class extends k{constructor(t={}){super();this.client=(0,kt.createClient)(t),this.client.once("ready",()=>{this.connectionClosed=!1,this.emit("ready")}),this.client.once("end",()=>{this.connectionClosed=!0,this.emit("end")}),this.client.end=Dt}set(t,i,e,n){e.exists&&e.expire?this.client.set(t,i,e.expire.mode,e.expire.value,e.exists,n):e.expire?this.client.set(t,i,e.expire.mode,e.expire.value,n):e.exists?this.client.set(t,i,e.exists,n):this.client.set(t,i,n)}zadd(t,i,e,n){this.client.zadd(t,i,e,n)}multi(){return new K(this.client)}watch(t,i){this.client.watch(t,i)}unwatch(t){this.client.unwatch(t)}sismember(t,i,e){this.client.sismember(t,i,e)}sscan(t,i,e,n){let s=[t,i];e.MATCH&&s.push("MATCH",e.MATCH),e.COUNT&&s.push("COUNT",String(e.COUNT)),this.client.sscan(...s,(l,[a,c])=>{l?n(l):n(null,{cursor:a,items:c})})}zscan(t,i,e,n){let s=[t,i];e.MATCH&&s.push("MATCH",e.MATCH),e.COUNT&&s.push("COUNT",String(e.COUNT)),this.client.zscan(...s,(l,a)=>{if(l)n(l);else if(!a)n(new b);else{let c=new Set,[d,m]=a;for(;m.length;){let O=String(m.shift()),wt=String(m.shift());c.add(O)}n(null,{cursor:d,items:[...c]})}})}zcard(t,i){this.client.zcard(t,i)}zrange(t,i,e,n){this.client.zrange(t,i,e,n)}zrevrange(t,i,e,n){this.client.zrevrange(t,i,e,n)}psubscribe(t){this.client.psubscribe(t)}punsubscribe(t){this.client.punsubscribe(t)}subscribe(t){this.client.subscribe(t)}unsubscribe(t){this.client.unsubscribe(t)}zrangebyscore(t,i,e,n,s,l){this.client.zrangebyscore(t,i,e,"LIMIT",n,s,l)}zrem(t,i,e){this.client.zrem(t,i,e)}smembers(t,i){this.client.smembers(t,i)}sadd(t,i,e){this.client.sadd(t,i,e)}srem(t,i,e){this.client.srem(t,i,e)}hgetall(t,i){this.client.hgetall(t,(e,n)=>{e?i(e):i(null,n!=null?n:{})})}hscan(t,i,e,n){let s=[t,i];e.MATCH&&s.push("MATCH",e.MATCH),e.COUNT&&s.push("COUNT",String(e.COUNT)),this.client.hscan(...s,(l,[a,c])=>{if(l)n(l);else{let d={};for(;c.length;){let m=String(c.shift());d[m]=String(c.shift())}n(null,{cursor:a,result:d})}})}hget(t,i,e){this.client.hget(t,i,e)}hset(t,i,e,n){this.client.hset(t,i,String(e),n)}hdel(t,i,e){this.client.hdel(t,...typeof i=="string"?[i]:i,e)}lrange(t,i,e,n){this.client.lrange(t,i,e,n)}hkeys(t,i){this.client.hkeys(t,i)}hlen(t,i){this.client.hlen(t,i)}brpoplpush(t,i,e,n){this.client.brpoplpush(t,i,e,n)}rpoplpush(t,i,e){this.client.rpoplpush(t,i,e)}zrangebyscorewithscores(t,i,e,n){this.client.zrangebyscore(t,i,e,"WITHSCORES",(s,l)=>{if(s)n(s);else{let a=l!=null?l:[],c={};for(let d=a.splice(0,2);d.length>0;d=a.splice(0,2)){let[m,O]=d;c[O]=m}n(null,c)}})}rpop(t,i){this.client.rpop(t,i)}lrem(t,i,e,n){this.client.lrem(t,i,e,n)}publish(t,i,e){this.client.publish(t,i,e)}flushall(t){this.client.flushall(t)}loadScript(t,i){this.client.script("load",t,i)}evalsha(t,i,e){let n=[t],s=Array.isArray(i)?i:[i];this.client.evalsha(n.concat(s),(l,a)=>e(l,a))}get(t,i){this.client.get(t,i)}del(t,i){this.client.del(...typeof t=="string"?[t]:t,i)}llen(t,i){this.client.llen(t,i)}lmove(t,i,e,n,s){this.validateRedisVersion(6,2)?this.client.lmove(t,i,e,n,s):s(new u("Command not supported by your Redis server. Minimal required Redis server version is 6.2.0."))}zremrangebyscore(t,i,e,n){this.client.zremrangebyscore(t,i,e,n)}hmget(t,i,e){this.client.hmget(t,i,e)}halt(t){this.connectionClosed?t():(this.client.once("end",t),this.end(!0))}end(t){this.connectionClosed||this.client.end(t)}quit(t=()=>{}){this.connectionClosed?t():(this.client.once("end",t),this.client.quit())}getInfo(t){this.client.info(t)}on(t,i){return this.client.on(t,i),this}};var Ct=require("@redis/client");var vt=require("@redis/client");var $=class{constructor(r){this.multi=r.multi()}lrem(r,t,i){return this.multi.lRem(r,t,i),this}lpop(r){return this.multi.lPop(r),this}lpush(r,t){return this.multi.lPush(r,t),this}ltrim(r,t,i){return this.multi.lTrim(r,t,i),this}rpop(r){return this.multi.rPop(r),this}rpush(r,t){return this.multi.rPush(r,t),this}zadd(r,t,i){return this.multi.zAdd(r,{score:t,value:i}),this}zrem(r,t){return this.multi.zRem(r,t),this}sadd(r,t){return this.multi.sAdd(r,t),this}srem(r,t){return this.multi.sRem(r,t),this}hset(r,t,i){return this.multi.hSet(r,t,i),this}hdel(r,t){return this.multi.hDel(r,t),this}hincrby(r,t,i){return this.multi.hIncrBy(r,t,i),this}pexpire(r,t){return this.multi.pExpire(r,t),this}expire(r,t){return this.multi.expire(r,t),this}rpoplpush(r,t){return this.multi.rPopLPush(r,t),this}del(r){return this.multi.del(r),this}exec(r){this.multi.exec().then(t=>r(null,t)).catch(t=>{t instanceof vt.WatchError?r(new f):r(t)})}};var J=class extends k{constructor(t={}){super();this.client=(0,Ct.createClient)(t),this.client.once("ready",()=>{this.connectionClosed=!1,this.emit("ready")}),this.client.once("end",()=>{this.connectionClosed=!0,this.emit("end")}),this.client.connect()}set(t,i,e,n){this.client.set(t,i,V(V({},e.expire?{[e.expire.mode]:e.expire.value}:{}),e.exists?{[e.exists]:!0}:{})).then(s=>n(null,s)).catch(n)}zadd(t,i,e,n){this.client.zAdd(t,{score:i,value:e}).then(s=>n(null,s)).catch(n)}multi(){return new $(this.client)}watch(t,i){this.client.watch(t).then(e=>i(null,e)).catch(i)}unwatch(t){this.client.unwatch().then(i=>t(null,i)).catch(t)}sismember(t,i,e){this.client.sIsMember(t,i).then(n=>e(null,Number(n))).catch(e)}zcard(t,i){this.client.zCard(t).then(e=>i(null,e)).catch(i)}zrange(t,i,e,n){this.client.zRange(t,i,e).then(s=>n(null,(Array.isArray(s)?s:[]).map(l=>String(l)))).catch(n)}zrevrange(t,i,e,n){this.client.sendCommand(["ZREVRANGE",t,String(i),String(e)]).then(s=>n(null,(Array.isArray(s)?s:[]).map(l=>String(l)))).catch(n)}zrem(t,i,e){this.client.zRem(t,i).then(n=>e(null,n)).catch(e)}psubscribe(t){this.client.pSubscribe(t,(i,e)=>{this.client.emit("pmessage",t,e,i)})}punsubscribe(t){this.client.pUnsubscribe(t).catch(()=>{})}subscribe(t){this.client.subscribe(t,(i,e)=>{this.client.emit("message",e,i)})}unsubscribe(t){this.client.unsubscribe(t).catch(()=>{})}zrangebyscore(t,i,e,n,s,l){this.client.zRangeByScore(t,i,e,{LIMIT:{offset:n,count:s}}).then(a=>l(null,a)).catch(l)}smembers(t,i){this.client.sMembers(t).then(e=>i(null,e)).catch(i)}sscan(t,i,e,n){let s=[t,Number(i),e];this.client.sScan(...s).then(({cursor:l,members:a})=>{n(null,{cursor:String(l),items:a})}).catch(n)}zscan(t,i,e,n){let s=[t,Number(i),e];this.client.zScan(...s).then(({cursor:l,members:a})=>{let c=new Set;for(let d of a)c.add(d.value);n(null,{cursor:String(l),items:[...c]})}).catch(n)}sadd(t,i,e){this.client.sAdd(t,i).then(n=>e(null,n)).catch(e)}srem(t,i,e){this.client.sRem(t,i).then(n=>e(null,n)).catch(e)}hgetall(t,i){this.client.hGetAll(t).then(e=>i(null,e)).catch(i)}hscan(t,i,e,n){let s=[t,Number(i),e];this.client.hScan(...s).then(({cursor:l,tuples:a})=>{let c={};for(;a.length;){let d=a.shift();d&&(c[d.field]=d.value)}n(null,{cursor:String(l),result:c})}).catch(n)}hget(t,i,e){this.client.hGet(t,i).then(n=>e(null,n!=null?n:null)).catch(e)}hset(t,i,e,n){this.client.hSet(t,i,e).then(s=>n(null,s)).catch(n)}hdel(t,i,e){this.client.hDel(t,i).then(n=>e(null,Number(n))).catch(e)}lrange(t,i,e,n){this.client.lRange(t,i,e).then(s=>n(null,s)).catch(n)}hkeys(t,i){this.client.hKeys(t).then(e=>i(null,e)).catch(i)}hlen(t,i){this.client.hLen(t).then(e=>i(null,e)).catch(i)}brpoplpush(t,i,e,n){this.client.brPopLPush(t,i,e).then(s=>n(null,s)).catch(n)}rpoplpush(t,i,e){this.client.rPopLPush(t,i).then(n=>e(null,n)).catch(e)}zrangebyscorewithscores(t,i,e,n){this.client.zRangeByScoreWithScores(t,i,e).then(s=>{let l={};for(let{score:a,value:c}of s)l[a]=c;n(null,l)}).catch(n)}rpop(t,i){this.client.rPop(t).then(e=>i(null,e)).catch(i)}lrem(t,i,e,n){this.client.lRem(t,i,e).then(s=>n(null,s)).catch(n)}publish(t,i,e){this.client.publish(t,i).then(n=>e(null,n)).catch(e)}flushall(t){this.client.flushAll().then(i=>t(null,i)).catch(t)}loadScript(t,i){this.client.sendCommand(["SCRIPT","LOAD",t]).then(e=>i(null,typeof e=="string"?e:String(e))).catch(i)}evalsha(t,i,e){let n=[t],s=Array.isArray(i)?i:[i];this.client.sendCommand(["evalsha",...n.concat(s).map(l=>String(l))]).then(l=>{Array.isArray(l)?e(null,l.map(a=>a instanceof Buffer?a.toString():a)):l instanceof Buffer?e(null,l.toString()):e(null,l)}).catch(e)}get(t,i){this.client.sendCommand(["get",t]).then(e=>i(null,typeof e=="string"?e:null)).catch(i)}del(t,i){this.client.del(t).then(e=>i(null,e)).catch(i)}llen(t,i){this.client.sendCommand(["llen",t]).then(e=>i(null,Number(e))).catch(i)}lmove(t,i,e,n,s){this.validateRedisVersion(6,2)?this.client.lMove(t,i,e,n).then(l=>s(null,l)).catch(s):s(new u("Command not supported by your Redis server. Minimal required Redis server version is 6.2.0."))}zremrangebyscore(t,i,e,n){this.client.sendCommand(["zremrangebyscore",t,`${i}`,`${e}`]).then(s=>n(null,Number(s))).catch(n)}hmget(t,i,e){this.client.hmGet(t,i).then(n=>e(null,n)).catch(e)}halt(t){this.connectionClosed?t():(this.client.once("end",t),this.end())}end(){this.connectionClosed||this.client.disconnect().catch(()=>{})}quit(t=()=>{}){this.connectionClosed?t():(this.client.once("end",t),this.client.quit())}getInfo(t){this.client.info().then(i=>t(null,i)).catch(t)}on(t,i){return this.client.on(t,i),this}};var ft=j(require("ioredis"),1);var B=class{constructor(r){this.multi=r.multi()}lrem(r,t,i){return this.multi.lrem(r,t,i),this}lpop(r){return this.multi.lpop(r),this}lpush(r,t){return this.multi.lpush(r,t),this}ltrim(r,t,i){return this.multi.ltrim(r,t,i),this}rpop(r){return this.multi.rpop(r),this}rpush(r,t){return this.multi.rpush(r,t),this}zadd(r,t,i){return this.multi.zadd(r,t,i),this}zrem(r,t){return this.multi.zrem(r,...typeof t=="string"?[t]:t),this}sadd(r,t){return this.multi.sadd(r,t),this}srem(r,t){return this.multi.srem(r,...typeof t=="string"?[t]:t),this}hset(r,t,i){return this.multi.hset(r,t,i),this}hdel(r,t){return this.multi.hdel(r,...typeof t=="string"?[t]:t),this}hincrby(r,t,i){return this.multi.hincrby(r,t,i),this}pexpire(r,t){return this.multi.pexpire(r,t),this}expire(r,t){return this.multi.expire(r,t),this}rpoplpush(r,t){return this.multi.rpoplpush(r,t),this}del(r){return this.multi.del(...typeof r=="string"?[r]:r),this}exec(r){this.multi.exec((t,i)=>{if(t)r(t);else if(!i)r(new f);else{let e=[],n=null;for(let s of i){if(!Array.isArray(s)){n=new u("Expected an array reply from multi.exec()");break}let[l,a]=s;if(l instanceof Error){n=l;break}e.push(a)}n?r(n):r(null,e)}})}};var Z=class extends k{constructor(t={}){super();this.client=new ft.default(t),this.client.once("ready",()=>{this.connectionClosed=!1,this.emit("ready")}),this.client.once("end",()=>{this.connectionClosed=!0,this.emit("end")})}set(t,i,e,n){e.exists&&e.expire?this.client.set(t,i,e.expire.mode,e.expire.value,e.exists,n):e.expire?this.client.set(t,i,e.expire.mode,e.expire.value,n):e.exists?this.client.set(t,i,e.exists,n):this.client.set(t,i,n)}zadd(t,i,e,n){this.client.zadd(t,i,e,n)}multi(){return new B(this.client)}watch(t,i){this.client.watch(t,i)}unwatch(t){this.client.unwatch(t)}sismember(t,i,e){this.client.sismember(t,i,e)}sscan(t,i,e,n){let s=[t,i];e.MATCH&&s.push("MATCH",e.MATCH),e.COUNT&&s.push("COUNT",String(e.COUNT)),this.client.sscan(...s,(l,[a,c])=>{l?n(l):n(null,{cursor:a,items:c})})}zcard(t,i){this.client.zcard(t,i)}zrange(t,i,e,n){this.client.zrange(t,i,e,n)}zscan(t,i,e,n){let s=[t,i];e.MATCH&&s.push("MATCH",e.MATCH),e.COUNT&&s.push("COUNT",String(e.COUNT)),this.client.zscan(...s,(l,a)=>{if(l)n(l);else if(!a)n(new b);else{let c=new Set,[d,m]=a;for(;m.length;){let O=String(m.shift()),wt=String(m.shift());c.add(O)}n(null,{cursor:d,items:[...c]})}})}zrevrange(t,i,e,n){this.client.zrevrange(t,i,e,n)}zrem(t,i,e){this.client.zrem(t,i,e)}psubscribe(t){this.client.psubscribe(t)}punsubscribe(t){this.client.punsubscribe(t)}subscribe(t){this.client.subscribe(t)}unsubscribe(t){this.client.unsubscribe(t)}zrangebyscore(t,i,e,n,s,l){this.client.zrangebyscore(t,i,e,"LIMIT",n,s,l)}smembers(t,i){this.client.smembers(t,i)}sadd(t,i,e){this.client.sadd(t,i,e)}srem(t,i,e){this.client.srem(t,i,e)}hgetall(t,i){this.client.hgetall(t,i)}hscan(t,i,e,n){let s=[t,i];e.MATCH&&s.push("MATCH",e.MATCH),e.COUNT&&s.push("COUNT",String(e.COUNT)),this.client.hscan(...s,(l,[a,c])=>{if(l)n(l);else{let d={};for(;c.length;){let m=String(c.shift());d[m]=String(c.shift())}n(null,{cursor:a,result:d})}})}hget(t,i,e){this.client.hget(t,i,e)}hset(t,i,e,n){this.client.hset(t,i,e,n)}hdel(t,i,e){this.client.hdel(t,i,e)}lrange(t,i,e,n){this.client.lrange(t,i,e,n)}hkeys(t,i){this.client.hkeys(t,i)}hlen(t,i){this.client.hlen(t,i)}brpoplpush(t,i,e,n){this.client.brpoplpush(t,i,e,n)}rpoplpush(t,i,e){this.client.rpoplpush(t,i,e)}zrangebyscorewithscores(t,i,e,n){this.client.zrangebyscore(t,i,e,"WITHSCORES",(s,l)=>{if(s)n(s);else{let a=l!=null?l:[],c={};for(let d=a.splice(0,2);d.length>0;d=a.splice(0,2)){let[m,O]=d;c[O]=m}n(null,c)}})}rpop(t,i){this.client.rpop(t,i)}lrem(t,i,e,n){this.client.lrem(t,i,e,n)}publish(t,i,e){this.client.publish(t,i,e)}flushall(t){this.client.flushall(t)}loadScript(t,i){this.client.script("load",t,i)}evalsha(t,i,e){let n=[t],s=Array.isArray(i)?i:[i];this.client.evalsha(n.concat(s),e)}get(t,i){this.client.get(t,i)}del(t,i){this.client.del(t,i)}llen(t,i){this.client.llen(t,i)}lmove(t,i,e,n,s){this.validateRedisVersion(6,2)?this.client.lmove(t,i,e,n,s):s(new u("Command not supported by your Redis server. Minimal required Redis server version is 6.2.0."))}zremrangebyscore(t,i,e,n){this.client.zremrangebyscore(t,i,e,n)}hmget(t,i,e){this.client.hmget(t,i,e)}halt(t){this.connectionClosed?t():(this.client.once("end",t),this.end())}end(){this.connectionClosed||this.client.disconnect(!1)}quit(t=()=>{}){this.connectionClosed?t():(this.client.once("end",t),this.client.quit())}getInfo(t){this.client.info(t)}on(t,i){return this.client.on(t,i),this}};function Vt(o){return o.client==="redis"?new Q(o.options):o.client==="redis_v4"?new J(o.options):new Z(o.options)}function Gt(o,r){let t=Vt(o);t.once("ready",()=>{v.waterfall([i=>t.validateRedisServerSupport(i),i=>t.loadScripts(i)],i=>{if(i)throw i;r(null,t)})})}var It={createInstance:Gt};0&&(module.exports={CallbackEmptyReplyError,CallbackInvalidReplyError,ERedisConfigClient,Lock,LockAbortError,LockAcquireError,LockError,LockExtendError,LockMethodNotAllowedError,LockNotAcquiredError,LockNotReleasedError,LoggerError,PanicError,PowerSwitch,PowerSwitchError,RedisClient,RedisClientError,RedisSMQError,Ticker,TickerError,WatchedKeysChangedError,Worker,WorkerError,WorkerPool,WorkerRunner,async,events,logger,redis});
|
|
4
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,464 @@
|
|
|
1
|
+
import { RedisClientMultiCommandType } from '@redis/client/dist/lib/client/multi-command';
|
|
2
|
+
import { RedisClientOptions, RedisModules, RedisFunctions, RedisScripts, RedisClientType } from '@redis/client';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import * as Logger from 'bunyan';
|
|
5
|
+
import { RedisOptions } from 'ioredis';
|
|
6
|
+
import { ClientOpts } from 'redis';
|
|
7
|
+
|
|
8
|
+
interface ICallback<T> {
|
|
9
|
+
(err?: Error | null, reply?: T): void;
|
|
10
|
+
(err: undefined | null, reply: T): void;
|
|
11
|
+
}
|
|
12
|
+
type TFunction<TReturn = void, TArgs = any> = (...args: TArgs[]) => TReturn;
|
|
13
|
+
type TUnaryFunction<T, E = void> = (reply: T) => E;
|
|
14
|
+
|
|
15
|
+
interface IRedisConfigIORedis {
|
|
16
|
+
client: ERedisConfigClient.IOREDIS;
|
|
17
|
+
options?: RedisOptions;
|
|
18
|
+
}
|
|
19
|
+
declare enum ERedisConfigClient {
|
|
20
|
+
REDIS = "redis",
|
|
21
|
+
IOREDIS = "ioredis",
|
|
22
|
+
REDIS_V4 = "redis_v4"
|
|
23
|
+
}
|
|
24
|
+
interface IRedisConfigNodeRedis {
|
|
25
|
+
client: ERedisConfigClient.REDIS;
|
|
26
|
+
options?: ClientOpts;
|
|
27
|
+
}
|
|
28
|
+
interface IRedisConfigNodeRedisV4 {
|
|
29
|
+
client: ERedisConfigClient.REDIS_V4;
|
|
30
|
+
options?: RedisClientOptions;
|
|
31
|
+
}
|
|
32
|
+
type IRedisConfig = IRedisConfigIORedis | IRedisConfigNodeRedis | IRedisConfigNodeRedisV4;
|
|
33
|
+
|
|
34
|
+
type TRedisTransactionNodeRedisV4 = RedisClientMultiCommandType<RedisModules, RedisFunctions, RedisScripts>;
|
|
35
|
+
type TRedisClientNodeRedisV4 = RedisClientType<RedisModules, RedisFunctions, RedisScripts>;
|
|
36
|
+
interface IRedisClient {
|
|
37
|
+
validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
|
|
38
|
+
validateRedisServerSupport(cb: ICallback<void>): void;
|
|
39
|
+
set(key: string, value: string, options: {
|
|
40
|
+
expire?: {
|
|
41
|
+
mode: 'EX' | 'PX';
|
|
42
|
+
value: number;
|
|
43
|
+
};
|
|
44
|
+
exists?: 'NX' | 'XX';
|
|
45
|
+
}, cb: ICallback<string | null>): void;
|
|
46
|
+
zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
|
|
47
|
+
multi(): IRedisTransaction;
|
|
48
|
+
watch(args: string[], cb: ICallback<string>): void;
|
|
49
|
+
unwatch(cb: ICallback<string>): void;
|
|
50
|
+
sismember(key: string, member: string, cb: ICallback<number>): void;
|
|
51
|
+
zcard(key: string, cb: ICallback<number>): void;
|
|
52
|
+
zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
53
|
+
zrevrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
54
|
+
psubscribe(pattern: string): void;
|
|
55
|
+
punsubscribe(channel: string): void;
|
|
56
|
+
subscribe(channel: string): void;
|
|
57
|
+
unsubscribe(channel: string): void;
|
|
58
|
+
zrangebyscore(key: string, min: number | string, max: number | string, offset: number, count: number, cb: ICallback<string[]>): void;
|
|
59
|
+
smembers(key: string, cb: ICallback<string[]>): void;
|
|
60
|
+
sscan(key: string, cursor: string, options: {
|
|
61
|
+
MATCH?: string;
|
|
62
|
+
COUNT?: number;
|
|
63
|
+
}, cb: ICallback<{
|
|
64
|
+
cursor: string;
|
|
65
|
+
items: string[];
|
|
66
|
+
}>): void;
|
|
67
|
+
sscanAll(key: string, options: {
|
|
68
|
+
MATCH?: string;
|
|
69
|
+
COUNT?: number;
|
|
70
|
+
}, cb: ICallback<string[]>): void;
|
|
71
|
+
sadd(key: string, member: string, cb: ICallback<number>): void;
|
|
72
|
+
srem(key: string, member: string, cb: ICallback<number>): void;
|
|
73
|
+
hgetall(key: string, cb: ICallback<Record<string, string>>): void;
|
|
74
|
+
hscan(key: string, cursor: string, options: {
|
|
75
|
+
MATCH?: string;
|
|
76
|
+
COUNT?: number;
|
|
77
|
+
}, cb: ICallback<{
|
|
78
|
+
cursor: string;
|
|
79
|
+
result: Record<string, string>;
|
|
80
|
+
}>): void;
|
|
81
|
+
hscanAll(key: string, options: {
|
|
82
|
+
MATCH?: string;
|
|
83
|
+
COUNT?: number;
|
|
84
|
+
}, cb: ICallback<Record<string, string>>): void;
|
|
85
|
+
hget(key: string, field: string, cb: ICallback<string | null>): void;
|
|
86
|
+
hset(key: string, field: string, value: string | number, cb: ICallback<number>): void;
|
|
87
|
+
hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
|
|
88
|
+
lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
|
|
89
|
+
hkeys(key: string, cb: ICallback<string[]>): void;
|
|
90
|
+
hlen(key: string, cb: ICallback<number>): void;
|
|
91
|
+
brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
|
|
92
|
+
rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
93
|
+
zpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
94
|
+
zscan(key: string, cursor: string, options: {
|
|
95
|
+
MATCH?: string;
|
|
96
|
+
COUNT?: number;
|
|
97
|
+
}, cb: ICallback<{
|
|
98
|
+
cursor: string;
|
|
99
|
+
items: string[];
|
|
100
|
+
}>): void;
|
|
101
|
+
lpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
102
|
+
zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
|
|
103
|
+
zrem(source: string, id: string, cb: ICallback<number>): void;
|
|
104
|
+
rpop(key: string, cb: ICallback<string | null>): void;
|
|
105
|
+
lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
|
|
106
|
+
publish(channel: string, message: string, cb: ICallback<number>): void;
|
|
107
|
+
flushall(cb: ICallback<string>): void;
|
|
108
|
+
loadScript(script: string, cb: ICallback<string>): void;
|
|
109
|
+
evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
|
|
110
|
+
get(key: string, cb: ICallback<string | null>): void;
|
|
111
|
+
del(key: string | string[], cb: ICallback<number>): void;
|
|
112
|
+
llen(key: string, cb: ICallback<number>): void;
|
|
113
|
+
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
|
|
114
|
+
zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
|
|
115
|
+
hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
|
|
116
|
+
halt(cb: ICallback<void>): void;
|
|
117
|
+
end(flush: boolean): void;
|
|
118
|
+
quit(cb: ICallback<void>): void;
|
|
119
|
+
getInfo(cb: ICallback<string>): void;
|
|
120
|
+
updateServerVersion(cb: ICallback<void>): void;
|
|
121
|
+
loadScripts(cb: ICallback<void>): void;
|
|
122
|
+
runScript(scriptName: string, keys: (string | number)[], args: (string | number)[], cb: ICallback<unknown>): void;
|
|
123
|
+
}
|
|
124
|
+
interface IRedisTransaction {
|
|
125
|
+
lrem(key: string, count: number, element: string): this;
|
|
126
|
+
lpop(key: string): this;
|
|
127
|
+
rpush(key: string, element: string): this;
|
|
128
|
+
rpop(key: string): this;
|
|
129
|
+
lpush(key: string, element: string): this;
|
|
130
|
+
hdel(key: string, field: string | string[]): this;
|
|
131
|
+
hincrby(key: string, field: string, by: number): this;
|
|
132
|
+
del(key: string | string[]): this;
|
|
133
|
+
srem(key: string, element: string | string[]): this;
|
|
134
|
+
sadd(key: string, element: string): this;
|
|
135
|
+
zrem(key: string, element: string | string[]): this;
|
|
136
|
+
zadd(key: string, score: number, element: string): this;
|
|
137
|
+
hset(key: string, field: string, value: string | number): this;
|
|
138
|
+
pexpire(key: string, millis: number): this;
|
|
139
|
+
expire(key: string, secs: number): this;
|
|
140
|
+
ltrim(key: string, start: number, stop: number): this;
|
|
141
|
+
rpoplpush(source: string, destination: string): this;
|
|
142
|
+
exec(cb: ICallback<unknown[]>): void;
|
|
143
|
+
}
|
|
144
|
+
declare module 'ioredis' {
|
|
145
|
+
interface Commands {
|
|
146
|
+
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
declare module 'redis' {
|
|
150
|
+
interface Commands<R> {
|
|
151
|
+
info(cb?: Callback<string>): R;
|
|
152
|
+
info(section?: string | string[], cb?: Callback<string>): R;
|
|
153
|
+
INFO(cb?: Callback<string>): R;
|
|
154
|
+
INFO(section?: string | string[], cb?: Callback<string>): R;
|
|
155
|
+
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
interface ILoggerConfig {
|
|
160
|
+
enabled: boolean;
|
|
161
|
+
options?: Partial<Logger.LoggerOptions>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
interface ILogger {
|
|
165
|
+
info(message: unknown, ...params: unknown[]): void;
|
|
166
|
+
warn(message: unknown, ...params: unknown[]): void;
|
|
167
|
+
error(message: unknown, ...params: unknown[]): void;
|
|
168
|
+
debug(message: unknown, ...params: unknown[]): void;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
declare abstract class RedisSMQError extends Error {
|
|
172
|
+
constructor(message?: string);
|
|
173
|
+
get name(): string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
declare class CallbackEmptyReplyError extends RedisSMQError {
|
|
177
|
+
constructor();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
declare class CallbackInvalidReplyError extends RedisSMQError {
|
|
181
|
+
constructor();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
declare class PanicError extends RedisSMQError {
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
declare class LoggerError extends RedisSMQError {
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
declare class TickerError extends RedisSMQError {
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
declare class LockError extends RedisSMQError {
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
declare class LockAbortError extends LockError {
|
|
197
|
+
constructor(message?: string);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare class LockAcquireError extends LockError {
|
|
201
|
+
constructor(message?: string);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
declare class LockExtendError extends LockError {
|
|
205
|
+
constructor(message?: string);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
declare class LockMethodNotAllowedError extends LockError {
|
|
209
|
+
constructor(message?: string);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
declare class LockNotAcquiredError extends LockError {
|
|
213
|
+
constructor(message?: string);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
declare class LockNotReleasedError extends LockError {
|
|
217
|
+
constructor(message?: string);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
declare class RedisClientError extends RedisSMQError {
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
declare class WatchedKeysChangedError extends RedisClientError {
|
|
224
|
+
constructor(msg?: string);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
declare class WorkerError extends PanicError {
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
declare class PowerSwitchError extends RedisSMQError {
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
declare abstract class RedisClient extends EventEmitter implements IRedisClient {
|
|
234
|
+
protected static redisServerVersion: number[] | null;
|
|
235
|
+
protected connectionClosed: boolean;
|
|
236
|
+
validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
|
|
237
|
+
validateRedisServerSupport(cb: ICallback<void>): void;
|
|
238
|
+
abstract set(key: string, value: string, options: {
|
|
239
|
+
expire?: {
|
|
240
|
+
mode: 'EX' | 'PX';
|
|
241
|
+
value: number;
|
|
242
|
+
};
|
|
243
|
+
exists?: 'NX' | 'XX';
|
|
244
|
+
}, cb: ICallback<string | null>): void;
|
|
245
|
+
abstract zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
|
|
246
|
+
abstract multi(): IRedisTransaction;
|
|
247
|
+
abstract watch(args: string[], cb: ICallback<string>): void;
|
|
248
|
+
abstract unwatch(cb: ICallback<string>): void;
|
|
249
|
+
abstract sismember(key: string, member: string, cb: ICallback<number>): void;
|
|
250
|
+
abstract zcard(key: string, cb: ICallback<number>): void;
|
|
251
|
+
abstract zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
252
|
+
abstract zrevrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
253
|
+
abstract psubscribe(pattern: string): void;
|
|
254
|
+
abstract punsubscribe(channel: string): void;
|
|
255
|
+
abstract subscribe(channel: string): void;
|
|
256
|
+
abstract unsubscribe(channel: string): void;
|
|
257
|
+
abstract zrangebyscore(key: string, min: number | string, max: number | string, offset: number, count: number, cb: ICallback<string[]>): void;
|
|
258
|
+
abstract smembers(key: string, cb: ICallback<string[]>): void;
|
|
259
|
+
abstract sscan(key: string, cursor: string, options: {
|
|
260
|
+
MATCH?: string;
|
|
261
|
+
COUNT?: number;
|
|
262
|
+
}, cb: ICallback<{
|
|
263
|
+
cursor: string;
|
|
264
|
+
items: string[];
|
|
265
|
+
}>): void;
|
|
266
|
+
sscanAll(key: string, options: {
|
|
267
|
+
MATCH?: string;
|
|
268
|
+
COUNT?: number;
|
|
269
|
+
}, cb: ICallback<string[]>): void;
|
|
270
|
+
abstract sadd(key: string, member: string, cb: ICallback<number>): void;
|
|
271
|
+
abstract srem(key: string, member: string, cb: ICallback<number>): void;
|
|
272
|
+
abstract hgetall(key: string, cb: ICallback<Record<string, string>>): void;
|
|
273
|
+
abstract hscan(key: string, cursor: string, options: {
|
|
274
|
+
MATCH?: string;
|
|
275
|
+
COUNT?: number;
|
|
276
|
+
}, cb: ICallback<{
|
|
277
|
+
cursor: string;
|
|
278
|
+
result: Record<string, string>;
|
|
279
|
+
}>): void;
|
|
280
|
+
hscanAll(key: string, options: {
|
|
281
|
+
MATCH?: string;
|
|
282
|
+
COUNT?: number;
|
|
283
|
+
}, cb: ICallback<Record<string, string>>): void;
|
|
284
|
+
abstract hget(key: string, field: string, cb: ICallback<string | null>): void;
|
|
285
|
+
abstract hset(key: string, field: string, value: string | number, cb: ICallback<number>): void;
|
|
286
|
+
abstract hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
|
|
287
|
+
abstract lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
|
|
288
|
+
abstract hkeys(key: string, cb: ICallback<string[]>): void;
|
|
289
|
+
abstract hlen(key: string, cb: ICallback<number>): void;
|
|
290
|
+
abstract brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
|
|
291
|
+
abstract rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
292
|
+
zpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
293
|
+
abstract zscan(key: string, cursor: string, options: {
|
|
294
|
+
MATCH?: string;
|
|
295
|
+
COUNT?: number;
|
|
296
|
+
}, cb: ICallback<{
|
|
297
|
+
cursor: string;
|
|
298
|
+
items: string[];
|
|
299
|
+
}>): void;
|
|
300
|
+
lpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
301
|
+
abstract zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
|
|
302
|
+
abstract zrem(source: string, id: string, cb: ICallback<number>): void;
|
|
303
|
+
abstract rpop(key: string, cb: ICallback<string | null>): void;
|
|
304
|
+
abstract lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
|
|
305
|
+
abstract publish(channel: string, message: string, cb: ICallback<number>): void;
|
|
306
|
+
abstract flushall(cb: ICallback<string>): void;
|
|
307
|
+
abstract loadScript(script: string, cb: ICallback<string>): void;
|
|
308
|
+
abstract evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
|
|
309
|
+
abstract get(key: string, cb: ICallback<string | null>): void;
|
|
310
|
+
abstract del(key: string | string[], cb: ICallback<number>): void;
|
|
311
|
+
abstract llen(key: string, cb: ICallback<number>): void;
|
|
312
|
+
abstract lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
|
|
313
|
+
abstract zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
|
|
314
|
+
abstract hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
|
|
315
|
+
abstract halt(cb: ICallback<void>): void;
|
|
316
|
+
abstract end(flush: boolean): void;
|
|
317
|
+
abstract quit(cb: ICallback<void>): void;
|
|
318
|
+
abstract getInfo(cb: ICallback<string>): void;
|
|
319
|
+
updateServerVersion(cb: ICallback<void>): void;
|
|
320
|
+
loadScripts(cb: ICallback<void>): void;
|
|
321
|
+
runScript(scriptName: string, keys: (string | number)[], args: (string | number)[], cb: ICallback<unknown>): void;
|
|
322
|
+
static addScript(name: string, content: string): void;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
declare enum ELockStatus {
|
|
326
|
+
unlocked = 0,
|
|
327
|
+
locking = 1,
|
|
328
|
+
locked = 2,
|
|
329
|
+
releasing = 3,
|
|
330
|
+
extending = 4,
|
|
331
|
+
extended = 5
|
|
332
|
+
}
|
|
333
|
+
declare class Lock {
|
|
334
|
+
protected readonly lockId: string;
|
|
335
|
+
protected readonly lockKey: string;
|
|
336
|
+
protected readonly retryOnFail: boolean;
|
|
337
|
+
protected readonly ttl: number;
|
|
338
|
+
protected readonly redisClient: RedisClient;
|
|
339
|
+
protected readonly autoExtend: boolean;
|
|
340
|
+
protected status: ELockStatus;
|
|
341
|
+
protected lockingTimer: NodeJS.Timeout | null;
|
|
342
|
+
protected autoExtendTimer: NodeJS.Timeout | null;
|
|
343
|
+
protected throwExceptions: boolean;
|
|
344
|
+
constructor(redisClient: RedisClient, lockKey: string, ttl: number, retryOnFail?: boolean, autoExtend?: boolean, throwExceptions?: boolean);
|
|
345
|
+
protected resetTimers(): void;
|
|
346
|
+
protected setUnlocked(): void;
|
|
347
|
+
protected setLocked(): void;
|
|
348
|
+
protected setExtended(): void;
|
|
349
|
+
protected extend(cb: ICallback<void>): void;
|
|
350
|
+
protected runAutoExtendTimer(): void;
|
|
351
|
+
acquireLock(cb: ICallback<void>): void;
|
|
352
|
+
extendLock(cb: ICallback<void>): void;
|
|
353
|
+
releaseLock(cb: ICallback<void>): void;
|
|
354
|
+
acquireOrExtend(cb: ICallback<ELockStatus>): void;
|
|
355
|
+
isLocked(): boolean;
|
|
356
|
+
isReleased(): boolean;
|
|
357
|
+
getId(): string;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
declare class PowerSwitch {
|
|
361
|
+
protected throwExceptionOnError: boolean;
|
|
362
|
+
protected isPowered: boolean;
|
|
363
|
+
protected pendingState: boolean | null;
|
|
364
|
+
constructor(throwExceptionOnError?: boolean);
|
|
365
|
+
protected switch(s: boolean): boolean;
|
|
366
|
+
isUp(): boolean;
|
|
367
|
+
isDown(): boolean;
|
|
368
|
+
isGoingUp(): boolean;
|
|
369
|
+
isGoingDown(): boolean;
|
|
370
|
+
isRunning(): boolean;
|
|
371
|
+
goingUp(): boolean;
|
|
372
|
+
goingDown(): boolean;
|
|
373
|
+
commit(): void;
|
|
374
|
+
rollback(): void;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
declare class Ticker extends EventEmitter {
|
|
378
|
+
protected powerManager: PowerSwitch;
|
|
379
|
+
protected onTickFn: TFunction;
|
|
380
|
+
protected onNextTickFn: TFunction | null;
|
|
381
|
+
protected time: number;
|
|
382
|
+
protected timeout: NodeJS.Timeout | null;
|
|
383
|
+
protected interval: NodeJS.Timeout | null;
|
|
384
|
+
protected shutdownTimeout: NodeJS.Timeout | null;
|
|
385
|
+
protected aborted: boolean;
|
|
386
|
+
constructor(onTickFn?: TFunction, time?: number);
|
|
387
|
+
protected shutdown(): void;
|
|
388
|
+
protected onTick(): void;
|
|
389
|
+
abort(): void;
|
|
390
|
+
quit(): void;
|
|
391
|
+
isTicking(): boolean;
|
|
392
|
+
nextTick(): void;
|
|
393
|
+
nextTickFn(fn: TFunction): void;
|
|
394
|
+
runTimer(): void;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
declare abstract class Worker {
|
|
398
|
+
private readonly ticker;
|
|
399
|
+
private readonly powerManager;
|
|
400
|
+
private readonly managed;
|
|
401
|
+
constructor(managed: boolean, timeout?: number);
|
|
402
|
+
private getTicker;
|
|
403
|
+
private getPowerManager;
|
|
404
|
+
private onTick;
|
|
405
|
+
run: () => void;
|
|
406
|
+
quit: (cb: ICallback<void>) => void;
|
|
407
|
+
abstract work(cb: ICallback<void>): void;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
declare class WorkerPool {
|
|
411
|
+
private pool;
|
|
412
|
+
work: (cb: ICallback<void>) => void;
|
|
413
|
+
add: (worker: Worker) => number;
|
|
414
|
+
clear: (cb: ICallback<void>) => void;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
declare class WorkerRunner extends EventEmitter {
|
|
418
|
+
private readonly powerManager;
|
|
419
|
+
private readonly ticker;
|
|
420
|
+
private readonly lock;
|
|
421
|
+
private readonly redisClient;
|
|
422
|
+
private readonly logger;
|
|
423
|
+
private readonly workerPool;
|
|
424
|
+
constructor(redisClient: RedisClient, keyLock: string, workerPool: WorkerPool, logger: ILogger);
|
|
425
|
+
private onTick;
|
|
426
|
+
private clearWorkerPool;
|
|
427
|
+
private stopTicker;
|
|
428
|
+
private releaseLock;
|
|
429
|
+
addWorker(instance: Worker): void;
|
|
430
|
+
run: () => void;
|
|
431
|
+
quit: (cb: ICallback<void>) => void;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
declare const events: {
|
|
435
|
+
GOING_UP: string;
|
|
436
|
+
UP: string;
|
|
437
|
+
GOING_DOWN: string;
|
|
438
|
+
DOWN: string;
|
|
439
|
+
ERROR: string;
|
|
440
|
+
TICK: string;
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
declare function destroy(): void;
|
|
444
|
+
declare function setLogger<T extends ILogger>(logger: T): void;
|
|
445
|
+
declare function getLogger(cfg: ILoggerConfig, ns?: string): ILogger;
|
|
446
|
+
declare const logger: {
|
|
447
|
+
getLogger: typeof getLogger;
|
|
448
|
+
setLogger: typeof setLogger;
|
|
449
|
+
destroy: typeof destroy;
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
declare const async: {
|
|
453
|
+
each: <T>(collection: Record<string, T> | T[], iteratee: (item: T, key: number | string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
454
|
+
eachIn: <T_1>(collection: Record<string, T_1>, iteratee: (item: T_1, key: string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
455
|
+
eachOf: <T_2>(collection: T_2[], iteratee: (item: T_2, key: number, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
456
|
+
waterfall: <T_3>(tasks: TFunction[], callback: ICallback<T_3>) => void;
|
|
457
|
+
};
|
|
458
|
+
|
|
459
|
+
declare function createInstance(config: IRedisConfig, cb: ICallback<RedisClient>): void;
|
|
460
|
+
declare const redis: {
|
|
461
|
+
createInstance: typeof createInstance;
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
export { CallbackEmptyReplyError, CallbackInvalidReplyError, ERedisConfigClient, type ICallback, type ILogger, type ILoggerConfig, type IRedisClient, type IRedisConfig, type IRedisConfigIORedis, type IRedisConfigNodeRedis, type IRedisConfigNodeRedisV4, type IRedisTransaction, Lock, LockAbortError, LockAcquireError, LockError, LockExtendError, LockMethodNotAllowedError, LockNotAcquiredError, LockNotReleasedError, LoggerError, PanicError, PowerSwitch, PowerSwitchError, RedisClient, RedisClientError, RedisSMQError, type TFunction, type TRedisClientNodeRedisV4, type TRedisTransactionNodeRedisV4, type TUnaryFunction, Ticker, TickerError, WatchedKeysChangedError, Worker, WorkerError, WorkerPool, WorkerRunner, async, events, logger, redis };
|