redis-smq-common 3.0.0-rc.7 → 3.0.0-rc.8
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/dist/index.d.ts +19 -475
- package/dist/index.js +46 -3
- package/dist/package.json +3 -0
- package/dist/src/async/async.d.ts +7 -0
- package/dist/src/async/async.js +80 -0
- package/dist/src/errors/callback-empty-reply.error.d.ts +4 -0
- package/dist/src/errors/callback-empty-reply.error.js +11 -0
- package/dist/src/errors/callback-invalid-reply.error.d.ts +4 -0
- package/dist/src/errors/callback-invalid-reply.error.js +11 -0
- package/dist/src/errors/index.d.ts +4 -0
- package/dist/src/errors/index.js +12 -0
- package/dist/src/errors/panic.error.d.ts +3 -0
- package/dist/src/errors/panic.error.js +8 -0
- package/dist/src/errors/redis-smq.error.d.ts +4 -0
- package/dist/src/errors/redis-smq.error.js +13 -0
- package/dist/src/event/event-emitter.d.ts +11 -0
- package/dist/src/event/event-emitter.js +8 -0
- package/dist/src/event/index.d.ts +1 -0
- package/dist/src/event/index.js +18 -0
- package/dist/src/lock/errors/index.d.ts +7 -0
- package/dist/src/lock/errors/index.js +18 -0
- package/dist/src/lock/errors/lock-abort.error.d.ts +4 -0
- package/dist/src/lock/errors/lock-abort.error.js +11 -0
- package/dist/src/lock/errors/lock-acquire.error.d.ts +4 -0
- package/dist/src/lock/errors/lock-acquire.error.js +11 -0
- package/dist/src/lock/errors/lock-extend.error.d.ts +4 -0
- package/dist/src/lock/errors/lock-extend.error.js +11 -0
- package/dist/src/lock/errors/lock-method-not-allowed.error.d.ts +4 -0
- package/dist/src/lock/errors/lock-method-not-allowed.error.js +11 -0
- package/dist/src/lock/errors/lock-not-acquired.error.d.ts +4 -0
- package/dist/src/lock/errors/lock-not-acquired.error.js +11 -0
- package/dist/src/lock/errors/lock-not-released.error.d.ts +4 -0
- package/dist/src/lock/errors/lock-not-released.error.js +11 -0
- package/dist/src/lock/errors/lock.error.d.ts +3 -0
- package/dist/src/lock/errors/lock.error.js +8 -0
- package/dist/src/lock/lock.d.ts +37 -0
- package/dist/src/lock/lock.js +192 -0
- package/dist/src/lock/redis-client/redis-client.d.ts +4 -0
- package/dist/src/lock/redis-client/redis-client.js +17 -0
- package/dist/src/lock/redis-client/redis-client.ts +26 -0
- package/dist/src/logger/errors/index.d.ts +1 -0
- package/dist/src/logger/errors/index.js +6 -0
- package/dist/src/logger/errors/logger.error.d.ts +3 -0
- package/dist/src/logger/errors/logger.error.js +8 -0
- package/dist/src/logger/logger.d.ts +10 -0
- package/dist/src/logger/logger.js +50 -0
- package/dist/src/power-switch/errors/index.d.ts +1 -0
- package/dist/src/power-switch/errors/index.js +6 -0
- package/dist/src/power-switch/errors/power-switch.error.d.ts +3 -0
- package/dist/src/power-switch/errors/power-switch.error.js +8 -0
- package/dist/src/power-switch/power-switch.d.ts +16 -0
- package/dist/src/power-switch/power-switch.js +63 -0
- package/dist/src/redis-client/clients/ioredis-client-multi.d.ts +24 -0
- package/dist/src/redis-client/clients/ioredis-client-multi.js +108 -0
- package/dist/src/redis-client/clients/ioredis-client.d.ts +80 -0
- package/dist/src/redis-client/clients/ioredis-client.js +260 -0
- package/dist/src/redis-client/clients/node-redis-client-multi.d.ts +23 -0
- package/dist/src/redis-client/clients/node-redis-client-multi.js +91 -0
- package/dist/src/redis-client/clients/node-redis-client.d.ts +80 -0
- package/dist/src/redis-client/clients/node-redis-client.js +364 -0
- package/dist/src/redis-client/errors/index.d.ts +2 -0
- package/dist/src/redis-client/errors/index.js +8 -0
- package/dist/src/redis-client/errors/redis-client.error.d.ts +3 -0
- package/dist/src/redis-client/errors/redis-client.error.js +8 -0
- package/dist/src/redis-client/errors/watched-keys-changed.error.d.ts +4 -0
- package/dist/src/redis-client/errors/watched-keys-changed.error.js +11 -0
- package/dist/src/redis-client/index.d.ts +7 -0
- package/dist/src/redis-client/index.js +31 -0
- package/dist/src/redis-client/lua-script.d.ts +19 -0
- package/dist/src/redis-client/lua-script.js +82 -0
- package/dist/src/redis-client/redis-client.d.ts +94 -0
- package/dist/src/redis-client/redis-client.js +140 -0
- package/dist/src/ticker/errors/index.d.ts +1 -0
- package/dist/src/ticker/errors/index.js +6 -0
- package/dist/src/ticker/errors/ticker.error.d.ts +3 -0
- package/dist/src/ticker/errors/ticker.error.js +8 -0
- package/dist/src/ticker/ticker.d.ts +23 -0
- package/dist/src/ticker/ticker.js +120 -0
- package/dist/src/worker/errors/index.d.ts +1 -0
- package/dist/src/worker/errors/index.js +6 -0
- package/dist/src/worker/errors/worker-error.d.ts +3 -0
- package/dist/src/worker/errors/worker-error.js +8 -0
- package/dist/src/worker/worker-runner/worker-pool.d.ts +8 -0
- package/dist/src/worker/worker-runner/worker-pool.js +31 -0
- package/dist/src/worker/worker-runner/worker-runner.d.ts +21 -0
- package/dist/src/worker/worker-runner/worker-runner.js +65 -0
- package/dist/src/worker/worker.d.ts +13 -0
- package/dist/src/worker/worker.js +62 -0
- package/dist/types/common.d.ts +6 -0
- package/dist/types/common.js +3 -0
- package/dist/types/event/event.d.ts +9 -0
- package/dist/types/event/event.js +3 -0
- package/dist/types/event/index.d.ts +1 -0
- package/dist/types/event/index.js +18 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +21 -0
- package/dist/types/logger/config.d.ts +5 -0
- package/dist/types/logger/config.js +3 -0
- package/dist/types/logger/index.d.ts +7 -0
- package/dist/types/logger/index.js +18 -0
- package/dist/types/redis/config.d.ts +15 -0
- package/dist/types/redis/config.js +9 -0
- package/dist/types/redis/index.d.ts +119 -0
- package/dist/types/redis/index.js +18 -0
- package/package.json +1 -3
- package/dist/index.cjs +0 -4
- package/dist/index.d.cts +0 -475
- /package/dist/{lua → src/lock/redis-client/lua}/extend-lock.lua +0 -0
- /package/dist/{lua → src/lock/redis-client/lua}/release-lock.lua +0 -0
- /package/dist/{lua → src/redis-client/lua}/lpoprpush.lua +0 -0
- /package/dist/{lua → src/redis-client/lua}/zpoprpush.lua +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,475 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
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
|
-
type TEvent = {
|
|
172
|
-
error: (err: Error) => void;
|
|
173
|
-
next: () => void;
|
|
174
|
-
up: () => void;
|
|
175
|
-
down: () => void;
|
|
176
|
-
goingUp: () => void;
|
|
177
|
-
goingDown: () => void;
|
|
178
|
-
tick: () => void;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
declare abstract class RedisSMQError extends Error {
|
|
182
|
-
constructor(message?: string);
|
|
183
|
-
get name(): string;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
declare class CallbackEmptyReplyError extends RedisSMQError {
|
|
187
|
-
constructor();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
declare class CallbackInvalidReplyError extends RedisSMQError {
|
|
191
|
-
constructor();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
declare class PanicError extends RedisSMQError {
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
declare class LoggerError extends RedisSMQError {
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
declare class TickerError extends RedisSMQError {
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
declare class LockError extends RedisSMQError {
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
declare class LockAbortError extends LockError {
|
|
207
|
-
constructor(message?: string);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
declare class LockAcquireError extends LockError {
|
|
211
|
-
constructor(message?: string);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
declare class LockExtendError extends LockError {
|
|
215
|
-
constructor(message?: string);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
declare class LockMethodNotAllowedError extends LockError {
|
|
219
|
-
constructor(message?: string);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
declare class LockNotAcquiredError extends LockError {
|
|
223
|
-
constructor(message?: string);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
declare class LockNotReleasedError extends LockError {
|
|
227
|
-
constructor(message?: string);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
declare class RedisClientError extends RedisSMQError {
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
declare class WatchedKeysChangedError extends RedisClientError {
|
|
234
|
-
constructor(msg?: string);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
declare class WorkerError extends PanicError {
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
declare class PowerSwitchError extends RedisSMQError {
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
declare abstract class RedisClient extends EventEmitter$1 implements IRedisClient {
|
|
244
|
-
protected static redisServerVersion: number[] | null;
|
|
245
|
-
protected connectionClosed: boolean;
|
|
246
|
-
validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
|
|
247
|
-
validateRedisServerSupport(cb: ICallback<void>): void;
|
|
248
|
-
abstract set(key: string, value: string, options: {
|
|
249
|
-
expire?: {
|
|
250
|
-
mode: 'EX' | 'PX';
|
|
251
|
-
value: number;
|
|
252
|
-
};
|
|
253
|
-
exists?: 'NX' | 'XX';
|
|
254
|
-
}, cb: ICallback<string | null>): void;
|
|
255
|
-
abstract zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
|
|
256
|
-
abstract multi(): IRedisTransaction;
|
|
257
|
-
abstract watch(args: string[], cb: ICallback<string>): void;
|
|
258
|
-
abstract unwatch(cb: ICallback<string>): void;
|
|
259
|
-
abstract sismember(key: string, member: string, cb: ICallback<number>): void;
|
|
260
|
-
abstract zcard(key: string, cb: ICallback<number>): void;
|
|
261
|
-
abstract zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
262
|
-
abstract zrevrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
|
|
263
|
-
abstract psubscribe(pattern: string): void;
|
|
264
|
-
abstract punsubscribe(channel: string): void;
|
|
265
|
-
abstract subscribe(channel: string): void;
|
|
266
|
-
abstract unsubscribe(channel: string): void;
|
|
267
|
-
abstract zrangebyscore(key: string, min: number | string, max: number | string, offset: number, count: number, cb: ICallback<string[]>): void;
|
|
268
|
-
abstract smembers(key: string, cb: ICallback<string[]>): void;
|
|
269
|
-
abstract sscan(key: string, cursor: string, options: {
|
|
270
|
-
MATCH?: string;
|
|
271
|
-
COUNT?: number;
|
|
272
|
-
}, cb: ICallback<{
|
|
273
|
-
cursor: string;
|
|
274
|
-
items: string[];
|
|
275
|
-
}>): void;
|
|
276
|
-
sscanAll(key: string, options: {
|
|
277
|
-
MATCH?: string;
|
|
278
|
-
COUNT?: number;
|
|
279
|
-
}, cb: ICallback<string[]>): void;
|
|
280
|
-
abstract sadd(key: string, member: string, cb: ICallback<number>): void;
|
|
281
|
-
abstract srem(key: string, member: string, cb: ICallback<number>): void;
|
|
282
|
-
abstract hgetall(key: string, cb: ICallback<Record<string, string>>): void;
|
|
283
|
-
abstract hscan(key: string, cursor: string, options: {
|
|
284
|
-
MATCH?: string;
|
|
285
|
-
COUNT?: number;
|
|
286
|
-
}, cb: ICallback<{
|
|
287
|
-
cursor: string;
|
|
288
|
-
result: Record<string, string>;
|
|
289
|
-
}>): void;
|
|
290
|
-
hscanAll(key: string, options: {
|
|
291
|
-
MATCH?: string;
|
|
292
|
-
COUNT?: number;
|
|
293
|
-
}, cb: ICallback<Record<string, string>>): void;
|
|
294
|
-
abstract hget(key: string, field: string, cb: ICallback<string | null>): void;
|
|
295
|
-
abstract hset(key: string, field: string, value: string | number, cb: ICallback<number>): void;
|
|
296
|
-
abstract hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
|
|
297
|
-
abstract lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
|
|
298
|
-
abstract hkeys(key: string, cb: ICallback<string[]>): void;
|
|
299
|
-
abstract hlen(key: string, cb: ICallback<number>): void;
|
|
300
|
-
abstract brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
|
|
301
|
-
abstract rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
302
|
-
zpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
303
|
-
abstract zscan(key: string, cursor: string, options: {
|
|
304
|
-
MATCH?: string;
|
|
305
|
-
COUNT?: number;
|
|
306
|
-
}, cb: ICallback<{
|
|
307
|
-
cursor: string;
|
|
308
|
-
items: string[];
|
|
309
|
-
}>): void;
|
|
310
|
-
lpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
|
|
311
|
-
abstract zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
|
|
312
|
-
abstract zrem(source: string, id: string, cb: ICallback<number>): void;
|
|
313
|
-
abstract rpop(key: string, cb: ICallback<string | null>): void;
|
|
314
|
-
abstract lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
|
|
315
|
-
abstract publish(channel: string, message: string, cb: ICallback<number>): void;
|
|
316
|
-
abstract flushall(cb: ICallback<string>): void;
|
|
317
|
-
abstract loadScript(script: string, cb: ICallback<string>): void;
|
|
318
|
-
abstract evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
|
|
319
|
-
abstract get(key: string, cb: ICallback<string | null>): void;
|
|
320
|
-
abstract del(key: string | string[], cb: ICallback<number>): void;
|
|
321
|
-
abstract llen(key: string, cb: ICallback<number>): void;
|
|
322
|
-
abstract lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
|
|
323
|
-
abstract zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
|
|
324
|
-
abstract hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
|
|
325
|
-
abstract halt(cb: ICallback<void>): void;
|
|
326
|
-
abstract end(flush: boolean): void;
|
|
327
|
-
abstract quit(cb: ICallback<void>): void;
|
|
328
|
-
abstract getInfo(cb: ICallback<string>): void;
|
|
329
|
-
updateServerVersion(cb: ICallback<void>): void;
|
|
330
|
-
loadScripts(cb: ICallback<void>): void;
|
|
331
|
-
runScript(scriptName: string, keys: (string | number)[], args: (string | number)[], cb: ICallback<unknown>): void;
|
|
332
|
-
static addScript(name: string, content: string): void;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
declare enum ELockStatus {
|
|
336
|
-
unlocked = 0,
|
|
337
|
-
locking = 1,
|
|
338
|
-
locked = 2,
|
|
339
|
-
releasing = 3,
|
|
340
|
-
extending = 4,
|
|
341
|
-
extended = 5
|
|
342
|
-
}
|
|
343
|
-
declare class Lock {
|
|
344
|
-
protected readonly lockId: string;
|
|
345
|
-
protected readonly lockKey: string;
|
|
346
|
-
protected readonly retryOnFail: boolean;
|
|
347
|
-
protected readonly ttl: number;
|
|
348
|
-
protected readonly redisClient: RedisClient;
|
|
349
|
-
protected readonly autoExtend: boolean;
|
|
350
|
-
protected status: ELockStatus;
|
|
351
|
-
protected lockingTimer: NodeJS.Timeout | null;
|
|
352
|
-
protected autoExtendTimer: NodeJS.Timeout | null;
|
|
353
|
-
protected throwExceptions: boolean;
|
|
354
|
-
constructor(redisClient: RedisClient, lockKey: string, ttl: number, retryOnFail?: boolean, autoExtend?: boolean, throwExceptions?: boolean);
|
|
355
|
-
protected resetTimers(): void;
|
|
356
|
-
protected setUnlocked(): void;
|
|
357
|
-
protected setLocked(): void;
|
|
358
|
-
protected setExtended(): void;
|
|
359
|
-
protected extend(cb: ICallback<void>): void;
|
|
360
|
-
protected runAutoExtendTimer(): void;
|
|
361
|
-
acquireLock(cb: ICallback<void>): void;
|
|
362
|
-
extendLock(cb: ICallback<void>): void;
|
|
363
|
-
releaseLock(cb: ICallback<void>): void;
|
|
364
|
-
acquireOrExtend(cb: ICallback<ELockStatus>): void;
|
|
365
|
-
isLocked(): boolean;
|
|
366
|
-
isReleased(): boolean;
|
|
367
|
-
getId(): string;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
declare class PowerSwitch {
|
|
371
|
-
protected throwExceptionOnError: boolean;
|
|
372
|
-
protected isPowered: boolean;
|
|
373
|
-
protected pendingState: boolean | null;
|
|
374
|
-
constructor(throwExceptionOnError?: boolean);
|
|
375
|
-
protected switch(s: boolean): boolean;
|
|
376
|
-
isUp(): boolean;
|
|
377
|
-
isDown(): boolean;
|
|
378
|
-
isGoingUp(): boolean;
|
|
379
|
-
isGoingDown(): boolean;
|
|
380
|
-
isRunning(): boolean;
|
|
381
|
-
goingUp(): boolean;
|
|
382
|
-
goingDown(): boolean;
|
|
383
|
-
commit(): void;
|
|
384
|
-
rollback(): void;
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
type TEventEmitterEvent = Record<string | symbol, (...args: any) => any>;
|
|
388
|
-
declare interface EventEmitter<Events extends TEventEmitterEvent> extends EventEmitter$1 {
|
|
389
|
-
on<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
390
|
-
once<E extends keyof Events>(event: E, listener: Events[E]): this;
|
|
391
|
-
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): boolean;
|
|
392
|
-
removeAllListeners<E extends keyof Events>(event?: E): this;
|
|
393
|
-
}
|
|
394
|
-
declare class EventEmitter<Events extends TEventEmitterEvent> extends EventEmitter$1 {
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
declare class Ticker extends EventEmitter<TEvent> {
|
|
398
|
-
protected powerManager: PowerSwitch;
|
|
399
|
-
protected onTickFn: TFunction;
|
|
400
|
-
protected onNextTickFn: TFunction | null;
|
|
401
|
-
protected time: number;
|
|
402
|
-
protected timeout: NodeJS.Timeout | null;
|
|
403
|
-
protected interval: NodeJS.Timeout | null;
|
|
404
|
-
protected shutdownTimeout: NodeJS.Timeout | null;
|
|
405
|
-
protected aborted: boolean;
|
|
406
|
-
constructor(onTickFn?: TFunction, time?: number);
|
|
407
|
-
protected shutdown(): void;
|
|
408
|
-
protected onTick(): void;
|
|
409
|
-
abort(): void;
|
|
410
|
-
quit(): void;
|
|
411
|
-
isTicking(): boolean;
|
|
412
|
-
nextTick(): void;
|
|
413
|
-
nextTickFn(fn: TFunction): void;
|
|
414
|
-
runTimer(): void;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
declare abstract class Worker {
|
|
418
|
-
private readonly ticker;
|
|
419
|
-
private readonly powerManager;
|
|
420
|
-
private readonly managed;
|
|
421
|
-
constructor(managed: boolean, timeout?: number);
|
|
422
|
-
private getTicker;
|
|
423
|
-
private getPowerManager;
|
|
424
|
-
private onTick;
|
|
425
|
-
run: () => void;
|
|
426
|
-
quit: (cb: ICallback<void>) => void;
|
|
427
|
-
abstract work(cb: ICallback<void>): void;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
declare class WorkerPool {
|
|
431
|
-
private pool;
|
|
432
|
-
work: (cb: ICallback<void>) => void;
|
|
433
|
-
add: (worker: Worker) => number;
|
|
434
|
-
clear: (cb: ICallback<void>) => void;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
declare class WorkerRunner extends EventEmitter<TEvent> {
|
|
438
|
-
private readonly powerManager;
|
|
439
|
-
private readonly ticker;
|
|
440
|
-
private readonly lock;
|
|
441
|
-
private readonly redisClient;
|
|
442
|
-
private readonly logger;
|
|
443
|
-
private readonly workerPool;
|
|
444
|
-
constructor(redisClient: RedisClient, keyLock: string, workerPool: WorkerPool, logger: ILogger);
|
|
445
|
-
private onTick;
|
|
446
|
-
private clearWorkerPool;
|
|
447
|
-
private stopTicker;
|
|
448
|
-
private releaseLock;
|
|
449
|
-
addWorker(instance: Worker): void;
|
|
450
|
-
run: () => void;
|
|
451
|
-
quit: (cb: ICallback<void>) => void;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
declare function destroy(): void;
|
|
455
|
-
declare function setLogger<T extends ILogger>(logger: T): void;
|
|
456
|
-
declare function getLogger(cfg: ILoggerConfig, ns?: string): ILogger;
|
|
457
|
-
declare const logger: {
|
|
458
|
-
getLogger: typeof getLogger;
|
|
459
|
-
setLogger: typeof setLogger;
|
|
460
|
-
destroy: typeof destroy;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
declare const async: {
|
|
464
|
-
each: <T>(collection: Record<string, T> | T[], iteratee: (item: T, key: number | string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
465
|
-
eachIn: <T_1>(collection: Record<string, T_1>, iteratee: (item: T_1, key: string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
466
|
-
eachOf: <T_2>(collection: T_2[], iteratee: (item: T_2, key: number, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
467
|
-
waterfall: <T_3>(tasks: TFunction[], callback: ICallback<T_3>) => void;
|
|
468
|
-
};
|
|
469
|
-
|
|
470
|
-
declare function createInstance(config: IRedisConfig, cb: ICallback<RedisClient>): void;
|
|
471
|
-
declare const redis: {
|
|
472
|
-
createInstance: typeof createInstance;
|
|
473
|
-
};
|
|
474
|
-
|
|
475
|
-
export { CallbackEmptyReplyError, CallbackInvalidReplyError, ERedisConfigClient, EventEmitter, 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 TEvent, type TEventEmitterEvent, type TFunction, type TRedisClientNodeRedisV4, type TRedisTransactionNodeRedisV4, type TUnaryFunction, Ticker, TickerError, WatchedKeysChangedError, Worker, WorkerError, WorkerPool, WorkerRunner, async, logger, redis };
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './src/errors';
|
|
3
|
+
export * from './src/logger/errors';
|
|
4
|
+
export * from './src/ticker/errors';
|
|
5
|
+
export * from './src/lock/errors';
|
|
6
|
+
export * from './src/redis-client/errors';
|
|
7
|
+
export * from './src/worker/errors';
|
|
8
|
+
export * from './src/power-switch/errors';
|
|
9
|
+
export { Lock } from './src/lock/lock';
|
|
10
|
+
export { PowerSwitch } from './src/power-switch/power-switch';
|
|
11
|
+
export { RedisClient } from './src/redis-client/redis-client';
|
|
12
|
+
export { Ticker } from './src/ticker/ticker';
|
|
13
|
+
export { Worker } from './src/worker/worker';
|
|
14
|
+
export { WorkerRunner } from './src/worker/worker-runner/worker-runner';
|
|
15
|
+
export { WorkerPool } from './src/worker/worker-runner/worker-pool';
|
|
16
|
+
export { logger } from './src/logger/logger';
|
|
17
|
+
export { async } from './src/async/async';
|
|
18
|
+
export { redis } from './src/redis-client';
|
|
19
|
+
export * from './src/event';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 p{constructor(t={}){super();this.client=Rt(t),this.client.once("ready",()=>{this.connectionClosed=!1,this.emit("ready")}),this.client.once("end",()=>{this.connectionClosed=!0,this.emit("end")}),this.client.end=Et}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 X(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,(o,[a,c])=>{o?n(o):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,(o,a)=>{if(o)n(o);else if(!a)n(new b);else{let c=new Set,[d,h]=a;for(;h.length;){let T=String(h.shift()),lt=String(h.shift());c.add(T)}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,o){this.client.zrangebyscore(t,i,e,"LIMIT",n,s,o)}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,(o,[a,c])=>{if(o)n(o);else{let d={};for(;c.length;){let h=String(c.shift());d[h]=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,o)=>{if(s)n(s);else{let a=o!=null?o:[],c={};for(let d=a.splice(0,2);d.length>0;d=a.splice(0,2)){let[h,T]=d;c[T]=h}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),(o,a)=>e(o,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}};import{createClient as St}from"@redis/client";import{WatchError as yt}from"@redis/client";var G=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 yt?r(new f):r(t)})}};var _=class extends p{constructor(t={}){super();this.client=St(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,H(H({},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 G(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(o=>String(o)))).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(o=>String(o)))).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,o){this.client.zRangeByScore(t,i,e,{LIMIT:{offset:n,count:s}}).then(a=>o(null,a)).catch(o)}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:o,members:a})=>{n(null,{cursor:String(o),items:a})}).catch(n)}zscan(t,i,e,n){let s=[t,Number(i),e];this.client.zScan(...s).then(({cursor:o,members:a})=>{let c=new Set;for(let d of a)c.add(d.value);n(null,{cursor:String(o),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:o,tuples:a})=>{let c={};for(;a.length;){let d=a.shift();d&&(c[d.field]=d.value)}n(null,{cursor:String(o),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 o={};for(let{score:a,value:c}of s)o[a]=c;n(null,o)}).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(o=>String(o))]).then(o=>{Array.isArray(o)?e(null,o.map(a=>a instanceof Buffer?a.toString():a)):o instanceof Buffer?e(null,o.toString()):e(null,o)}).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(o=>s(null,o)).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}};import Lt from"ioredis";var W=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[o,a]=s;if(o instanceof Error){n=o;break}e.push(a)}n?r(n):r(null,e)}})}};var K=class extends p{constructor(t={}){super();this.client=new Lt(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 W(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,(o,[a,c])=>{o?n(o):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,(o,a)=>{if(o)n(o);else if(!a)n(new b);else{let c=new Set,[d,h]=a;for(;h.length;){let T=String(h.shift()),lt=String(h.shift());c.add(T)}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,o){this.client.zrangebyscore(t,i,e,"LIMIT",n,s,o)}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,(o,[a,c])=>{if(o)n(o);else{let d={};for(;c.length;){let h=String(c.shift());d[h]=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,o)=>{if(s)n(s);else{let a=o!=null?o:[],c={};for(let d=a.splice(0,2);d.length>0;d=a.splice(0,2)){let[h,T]=d;c[T]=h}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 Mt(l){return l.client==="redis"?new q(l.options):l.client==="redis_v4"?new _(l.options):new K(l.options)}function Nt(l,r){let t=Mt(l);t.once("ready",()=>{k.waterfall([i=>t.validateRedisServerSupport(i),i=>t.loadScripts(i)],i=>{if(i)throw i;r(null,t)})})}var Ot={createInstance:Nt};export{b as CallbackEmptyReplyError,Q as CallbackInvalidReplyError,tt as ERedisConfigClient,P as EventEmitter,V as Lock,x as LockAbortError,E as LockAcquireError,m as LockError,N as LockExtendError,O as LockMethodNotAllowedError,A as LockNotAcquiredError,F as LockNotReleasedError,U as LoggerError,R as PanicError,I as PowerSwitch,w as PowerSwitchError,p as RedisClient,u as RedisClientError,g as RedisSMQError,L as Ticker,M as TickerError,f as WatchedKeysChangedError,B as Worker,y as WorkerError,J as WorkerPool,$ as WorkerRunner,k as async,Tt as logger,Ot as redis};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.redis = exports.async = exports.logger = exports.WorkerPool = exports.WorkerRunner = exports.Worker = exports.Ticker = exports.RedisClient = exports.PowerSwitch = exports.Lock = void 0;
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./src/errors"), exports);
|
|
20
|
+
__exportStar(require("./src/logger/errors"), exports);
|
|
21
|
+
__exportStar(require("./src/ticker/errors"), exports);
|
|
22
|
+
__exportStar(require("./src/lock/errors"), exports);
|
|
23
|
+
__exportStar(require("./src/redis-client/errors"), exports);
|
|
24
|
+
__exportStar(require("./src/worker/errors"), exports);
|
|
25
|
+
__exportStar(require("./src/power-switch/errors"), exports);
|
|
26
|
+
var lock_1 = require("./src/lock/lock");
|
|
27
|
+
Object.defineProperty(exports, "Lock", { enumerable: true, get: function () { return lock_1.Lock; } });
|
|
28
|
+
var power_switch_1 = require("./src/power-switch/power-switch");
|
|
29
|
+
Object.defineProperty(exports, "PowerSwitch", { enumerable: true, get: function () { return power_switch_1.PowerSwitch; } });
|
|
30
|
+
var redis_client_1 = require("./src/redis-client/redis-client");
|
|
31
|
+
Object.defineProperty(exports, "RedisClient", { enumerable: true, get: function () { return redis_client_1.RedisClient; } });
|
|
32
|
+
var ticker_1 = require("./src/ticker/ticker");
|
|
33
|
+
Object.defineProperty(exports, "Ticker", { enumerable: true, get: function () { return ticker_1.Ticker; } });
|
|
34
|
+
var worker_1 = require("./src/worker/worker");
|
|
35
|
+
Object.defineProperty(exports, "Worker", { enumerable: true, get: function () { return worker_1.Worker; } });
|
|
36
|
+
var worker_runner_1 = require("./src/worker/worker-runner/worker-runner");
|
|
37
|
+
Object.defineProperty(exports, "WorkerRunner", { enumerable: true, get: function () { return worker_runner_1.WorkerRunner; } });
|
|
38
|
+
var worker_pool_1 = require("./src/worker/worker-runner/worker-pool");
|
|
39
|
+
Object.defineProperty(exports, "WorkerPool", { enumerable: true, get: function () { return worker_pool_1.WorkerPool; } });
|
|
40
|
+
var logger_1 = require("./src/logger/logger");
|
|
41
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
42
|
+
var async_1 = require("./src/async/async");
|
|
43
|
+
Object.defineProperty(exports, "async", { enumerable: true, get: function () { return async_1.async; } });
|
|
44
|
+
var redis_client_2 = require("./src/redis-client");
|
|
45
|
+
Object.defineProperty(exports, "redis", { enumerable: true, get: function () { return redis_client_2.redis; } });
|
|
46
|
+
__exportStar(require("./src/event"), exports);
|
|
4
47
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ICallback, TFunction } from '../../types';
|
|
2
|
+
export declare const async: {
|
|
3
|
+
each: <T>(collection: Record<string, T> | T[], iteratee: (item: T, key: number | string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
4
|
+
eachIn: <T_1>(collection: Record<string, T_1>, iteratee: (item: T_1, key: string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
5
|
+
eachOf: <T_2>(collection: T_2[], iteratee: (item: T_2, key: number, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
|
|
6
|
+
waterfall: <T_3>(tasks: TFunction[], callback: ICallback<T_3>) => void;
|
|
7
|
+
};
|