Socket
Socket
Sign inDemoInstall

redis-smq-common

Package Overview
Dependencies
45
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-rc.7 to 3.0.0-rc.8

dist/package.json

494

dist/index.d.ts

@@ -1,475 +0,19 @@

import { RedisClientMultiCommandType } from '@redis/client/dist/lib/client/multi-command';
import { RedisClientOptions, RedisModules, RedisFunctions, RedisScripts, RedisClientType } from '@redis/client';
import { EventEmitter as EventEmitter$1 } from 'events';
import * as Logger from 'bunyan';
import { RedisOptions } from 'ioredis';
import { ClientOpts } from 'redis';
interface ICallback<T> {
(err?: Error | null, reply?: T): void;
(err: undefined | null, reply: T): void;
}
type TFunction<TReturn = void, TArgs = any> = (...args: TArgs[]) => TReturn;
type TUnaryFunction<T, E = void> = (reply: T) => E;
interface IRedisConfigIORedis {
client: ERedisConfigClient.IOREDIS;
options?: RedisOptions;
}
declare enum ERedisConfigClient {
REDIS = "redis",
IOREDIS = "ioredis",
REDIS_V4 = "redis_v4"
}
interface IRedisConfigNodeRedis {
client: ERedisConfigClient.REDIS;
options?: ClientOpts;
}
interface IRedisConfigNodeRedisV4 {
client: ERedisConfigClient.REDIS_V4;
options?: RedisClientOptions;
}
type IRedisConfig = IRedisConfigIORedis | IRedisConfigNodeRedis | IRedisConfigNodeRedisV4;
type TRedisTransactionNodeRedisV4 = RedisClientMultiCommandType<RedisModules, RedisFunctions, RedisScripts>;
type TRedisClientNodeRedisV4 = RedisClientType<RedisModules, RedisFunctions, RedisScripts>;
interface IRedisClient {
validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
validateRedisServerSupport(cb: ICallback<void>): void;
set(key: string, value: string, options: {
expire?: {
mode: 'EX' | 'PX';
value: number;
};
exists?: 'NX' | 'XX';
}, cb: ICallback<string | null>): void;
zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
multi(): IRedisTransaction;
watch(args: string[], cb: ICallback<string>): void;
unwatch(cb: ICallback<string>): void;
sismember(key: string, member: string, cb: ICallback<number>): void;
zcard(key: string, cb: ICallback<number>): void;
zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
zrevrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
psubscribe(pattern: string): void;
punsubscribe(channel: string): void;
subscribe(channel: string): void;
unsubscribe(channel: string): void;
zrangebyscore(key: string, min: number | string, max: number | string, offset: number, count: number, cb: ICallback<string[]>): void;
smembers(key: string, cb: ICallback<string[]>): void;
sscan(key: string, cursor: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<{
cursor: string;
items: string[];
}>): void;
sscanAll(key: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<string[]>): void;
sadd(key: string, member: string, cb: ICallback<number>): void;
srem(key: string, member: string, cb: ICallback<number>): void;
hgetall(key: string, cb: ICallback<Record<string, string>>): void;
hscan(key: string, cursor: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<{
cursor: string;
result: Record<string, string>;
}>): void;
hscanAll(key: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<Record<string, string>>): void;
hget(key: string, field: string, cb: ICallback<string | null>): void;
hset(key: string, field: string, value: string | number, cb: ICallback<number>): void;
hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
hkeys(key: string, cb: ICallback<string[]>): void;
hlen(key: string, cb: ICallback<number>): void;
brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
zpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
zscan(key: string, cursor: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<{
cursor: string;
items: string[];
}>): void;
lpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
zrem(source: string, id: string, cb: ICallback<number>): void;
rpop(key: string, cb: ICallback<string | null>): void;
lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
publish(channel: string, message: string, cb: ICallback<number>): void;
flushall(cb: ICallback<string>): void;
loadScript(script: string, cb: ICallback<string>): void;
evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
get(key: string, cb: ICallback<string | null>): void;
del(key: string | string[], cb: ICallback<number>): void;
llen(key: string, cb: ICallback<number>): void;
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
halt(cb: ICallback<void>): void;
end(flush: boolean): void;
quit(cb: ICallback<void>): void;
getInfo(cb: ICallback<string>): void;
updateServerVersion(cb: ICallback<void>): void;
loadScripts(cb: ICallback<void>): void;
runScript(scriptName: string, keys: (string | number)[], args: (string | number)[], cb: ICallback<unknown>): void;
}
interface IRedisTransaction {
lrem(key: string, count: number, element: string): this;
lpop(key: string): this;
rpush(key: string, element: string): this;
rpop(key: string): this;
lpush(key: string, element: string): this;
hdel(key: string, field: string | string[]): this;
hincrby(key: string, field: string, by: number): this;
del(key: string | string[]): this;
srem(key: string, element: string | string[]): this;
sadd(key: string, element: string): this;
zrem(key: string, element: string | string[]): this;
zadd(key: string, score: number, element: string): this;
hset(key: string, field: string, value: string | number): this;
pexpire(key: string, millis: number): this;
expire(key: string, secs: number): this;
ltrim(key: string, start: number, stop: number): this;
rpoplpush(source: string, destination: string): this;
exec(cb: ICallback<unknown[]>): void;
}
declare module 'ioredis' {
interface Commands {
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
}
}
declare module 'redis' {
interface Commands<R> {
info(cb?: Callback<string>): R;
info(section?: string | string[], cb?: Callback<string>): R;
INFO(cb?: Callback<string>): R;
INFO(section?: string | string[], cb?: Callback<string>): R;
lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
}
}
interface ILoggerConfig {
enabled: boolean;
options?: Partial<Logger.LoggerOptions>;
}
interface ILogger {
info(message: unknown, ...params: unknown[]): void;
warn(message: unknown, ...params: unknown[]): void;
error(message: unknown, ...params: unknown[]): void;
debug(message: unknown, ...params: unknown[]): void;
}
type TEvent = {
error: (err: Error) => void;
next: () => void;
up: () => void;
down: () => void;
goingUp: () => void;
goingDown: () => void;
tick: () => void;
};
declare abstract class RedisSMQError extends Error {
constructor(message?: string);
get name(): string;
}
declare class CallbackEmptyReplyError extends RedisSMQError {
constructor();
}
declare class CallbackInvalidReplyError extends RedisSMQError {
constructor();
}
declare class PanicError extends RedisSMQError {
}
declare class LoggerError extends RedisSMQError {
}
declare class TickerError extends RedisSMQError {
}
declare class LockError extends RedisSMQError {
}
declare class LockAbortError extends LockError {
constructor(message?: string);
}
declare class LockAcquireError extends LockError {
constructor(message?: string);
}
declare class LockExtendError extends LockError {
constructor(message?: string);
}
declare class LockMethodNotAllowedError extends LockError {
constructor(message?: string);
}
declare class LockNotAcquiredError extends LockError {
constructor(message?: string);
}
declare class LockNotReleasedError extends LockError {
constructor(message?: string);
}
declare class RedisClientError extends RedisSMQError {
}
declare class WatchedKeysChangedError extends RedisClientError {
constructor(msg?: string);
}
declare class WorkerError extends PanicError {
}
declare class PowerSwitchError extends RedisSMQError {
}
declare abstract class RedisClient extends EventEmitter$1 implements IRedisClient {
protected static redisServerVersion: number[] | null;
protected connectionClosed: boolean;
validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
validateRedisServerSupport(cb: ICallback<void>): void;
abstract set(key: string, value: string, options: {
expire?: {
mode: 'EX' | 'PX';
value: number;
};
exists?: 'NX' | 'XX';
}, cb: ICallback<string | null>): void;
abstract zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
abstract multi(): IRedisTransaction;
abstract watch(args: string[], cb: ICallback<string>): void;
abstract unwatch(cb: ICallback<string>): void;
abstract sismember(key: string, member: string, cb: ICallback<number>): void;
abstract zcard(key: string, cb: ICallback<number>): void;
abstract zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
abstract zrevrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
abstract psubscribe(pattern: string): void;
abstract punsubscribe(channel: string): void;
abstract subscribe(channel: string): void;
abstract unsubscribe(channel: string): void;
abstract zrangebyscore(key: string, min: number | string, max: number | string, offset: number, count: number, cb: ICallback<string[]>): void;
abstract smembers(key: string, cb: ICallback<string[]>): void;
abstract sscan(key: string, cursor: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<{
cursor: string;
items: string[];
}>): void;
sscanAll(key: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<string[]>): void;
abstract sadd(key: string, member: string, cb: ICallback<number>): void;
abstract srem(key: string, member: string, cb: ICallback<number>): void;
abstract hgetall(key: string, cb: ICallback<Record<string, string>>): void;
abstract hscan(key: string, cursor: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<{
cursor: string;
result: Record<string, string>;
}>): void;
hscanAll(key: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<Record<string, string>>): void;
abstract hget(key: string, field: string, cb: ICallback<string | null>): void;
abstract hset(key: string, field: string, value: string | number, cb: ICallback<number>): void;
abstract hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
abstract lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
abstract hkeys(key: string, cb: ICallback<string[]>): void;
abstract hlen(key: string, cb: ICallback<number>): void;
abstract brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
abstract rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
zpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
abstract zscan(key: string, cursor: string, options: {
MATCH?: string;
COUNT?: number;
}, cb: ICallback<{
cursor: string;
items: string[];
}>): void;
lpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
abstract zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
abstract zrem(source: string, id: string, cb: ICallback<number>): void;
abstract rpop(key: string, cb: ICallback<string | null>): void;
abstract lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
abstract publish(channel: string, message: string, cb: ICallback<number>): void;
abstract flushall(cb: ICallback<string>): void;
abstract loadScript(script: string, cb: ICallback<string>): void;
abstract evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
abstract get(key: string, cb: ICallback<string | null>): void;
abstract del(key: string | string[], cb: ICallback<number>): void;
abstract llen(key: string, cb: ICallback<number>): void;
abstract lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
abstract zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
abstract hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
abstract halt(cb: ICallback<void>): void;
abstract end(flush: boolean): void;
abstract quit(cb: ICallback<void>): void;
abstract getInfo(cb: ICallback<string>): void;
updateServerVersion(cb: ICallback<void>): void;
loadScripts(cb: ICallback<void>): void;
runScript(scriptName: string, keys: (string | number)[], args: (string | number)[], cb: ICallback<unknown>): void;
static addScript(name: string, content: string): void;
}
declare enum ELockStatus {
unlocked = 0,
locking = 1,
locked = 2,
releasing = 3,
extending = 4,
extended = 5
}
declare class Lock {
protected readonly lockId: string;
protected readonly lockKey: string;
protected readonly retryOnFail: boolean;
protected readonly ttl: number;
protected readonly redisClient: RedisClient;
protected readonly autoExtend: boolean;
protected status: ELockStatus;
protected lockingTimer: NodeJS.Timeout | null;
protected autoExtendTimer: NodeJS.Timeout | null;
protected throwExceptions: boolean;
constructor(redisClient: RedisClient, lockKey: string, ttl: number, retryOnFail?: boolean, autoExtend?: boolean, throwExceptions?: boolean);
protected resetTimers(): void;
protected setUnlocked(): void;
protected setLocked(): void;
protected setExtended(): void;
protected extend(cb: ICallback<void>): void;
protected runAutoExtendTimer(): void;
acquireLock(cb: ICallback<void>): void;
extendLock(cb: ICallback<void>): void;
releaseLock(cb: ICallback<void>): void;
acquireOrExtend(cb: ICallback<ELockStatus>): void;
isLocked(): boolean;
isReleased(): boolean;
getId(): string;
}
declare class PowerSwitch {
protected throwExceptionOnError: boolean;
protected isPowered: boolean;
protected pendingState: boolean | null;
constructor(throwExceptionOnError?: boolean);
protected switch(s: boolean): boolean;
isUp(): boolean;
isDown(): boolean;
isGoingUp(): boolean;
isGoingDown(): boolean;
isRunning(): boolean;
goingUp(): boolean;
goingDown(): boolean;
commit(): void;
rollback(): void;
}
type TEventEmitterEvent = Record<string | symbol, (...args: any) => any>;
declare interface EventEmitter<Events extends TEventEmitterEvent> extends EventEmitter$1 {
on<E extends keyof Events>(event: E, listener: Events[E]): this;
once<E extends keyof Events>(event: E, listener: Events[E]): this;
emit<E extends keyof Events>(event: E, ...args: Parameters<Events[E]>): boolean;
removeAllListeners<E extends keyof Events>(event?: E): this;
}
declare class EventEmitter<Events extends TEventEmitterEvent> extends EventEmitter$1 {
}
declare class Ticker extends EventEmitter<TEvent> {
protected powerManager: PowerSwitch;
protected onTickFn: TFunction;
protected onNextTickFn: TFunction | null;
protected time: number;
protected timeout: NodeJS.Timeout | null;
protected interval: NodeJS.Timeout | null;
protected shutdownTimeout: NodeJS.Timeout | null;
protected aborted: boolean;
constructor(onTickFn?: TFunction, time?: number);
protected shutdown(): void;
protected onTick(): void;
abort(): void;
quit(): void;
isTicking(): boolean;
nextTick(): void;
nextTickFn(fn: TFunction): void;
runTimer(): void;
}
declare abstract class Worker {
private readonly ticker;
private readonly powerManager;
private readonly managed;
constructor(managed: boolean, timeout?: number);
private getTicker;
private getPowerManager;
private onTick;
run: () => void;
quit: (cb: ICallback<void>) => void;
abstract work(cb: ICallback<void>): void;
}
declare class WorkerPool {
private pool;
work: (cb: ICallback<void>) => void;
add: (worker: Worker) => number;
clear: (cb: ICallback<void>) => void;
}
declare class WorkerRunner extends EventEmitter<TEvent> {
private readonly powerManager;
private readonly ticker;
private readonly lock;
private readonly redisClient;
private readonly logger;
private readonly workerPool;
constructor(redisClient: RedisClient, keyLock: string, workerPool: WorkerPool, logger: ILogger);
private onTick;
private clearWorkerPool;
private stopTicker;
private releaseLock;
addWorker(instance: Worker): void;
run: () => void;
quit: (cb: ICallback<void>) => void;
}
declare function destroy(): void;
declare function setLogger<T extends ILogger>(logger: T): void;
declare function getLogger(cfg: ILoggerConfig, ns?: string): ILogger;
declare const logger: {
getLogger: typeof getLogger;
setLogger: typeof setLogger;
destroy: typeof destroy;
};
declare const async: {
each: <T>(collection: Record<string, T> | T[], iteratee: (item: T, key: number | string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
eachIn: <T_1>(collection: Record<string, T_1>, iteratee: (item: T_1, key: string, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
eachOf: <T_2>(collection: T_2[], iteratee: (item: T_2, key: number, callback: ICallback<void>) => void, callback: ICallback<void>) => void;
waterfall: <T_3>(tasks: TFunction[], callback: ICallback<T_3>) => void;
};
declare function createInstance(config: IRedisConfig, cb: ICallback<RedisClient>): void;
declare const redis: {
createInstance: typeof createInstance;
};
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 };
export * from './types';
export * from './src/errors';
export * from './src/logger/errors';
export * from './src/ticker/errors';
export * from './src/lock/errors';
export * from './src/redis-client/errors';
export * from './src/worker/errors';
export * from './src/power-switch/errors';
export { Lock } from './src/lock/lock';
export { PowerSwitch } from './src/power-switch/power-switch';
export { RedisClient } from './src/redis-client/redis-client';
export { Ticker } from './src/ticker/ticker';
export { Worker } from './src/worker/worker';
export { WorkerRunner } from './src/worker/worker-runner/worker-runner';
export { WorkerPool } from './src/worker/worker-runner/worker-pool';
export { logger } from './src/logger/logger';
export { async } from './src/async/async';
export { redis } from './src/redis-client';
export * from './src/event';

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

var at=Object.defineProperty,ct=Object.defineProperties;var dt=Object.getOwnPropertyDescriptors;var Z=Object.getOwnPropertySymbols;var gt=Object.prototype.hasOwnProperty,ut=Object.prototype.propertyIsEnumerable;var j=(l,r,t)=>r in l?at(l,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):l[r]=t,H=(l,r)=>{for(var t in r||(r={}))gt.call(r,t)&&j(l,t,r[t]);if(Z)for(var t of Z(r))ut.call(r,t)&&j(l,t,r[t]);return l},Y=(l,r)=>ct(l,dt(r));var tt=(i=>(i.REDIS="redis",i.IOREDIS="ioredis",i.REDIS_V4="redis_v4",i))(tt||{});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 Q=class extends g{constructor(){super("Invalid reply type")}};var R=class extends g{};var U=class extends g{};var M=class extends g{};var m=class extends g{};var x=class extends m{constructor(r="releaseLock() may have been called. Abandoning."){super(r)}};var E=class extends m{constructor(r="Could not acquire a lock"){super(r)}};var N=class extends m{constructor(r="Acquired lock could not be extended"){super(r)}};var O=class extends m{constructor(r="This method can not be used when autoExtend is enabled"){super(r)}};var A=class extends m{constructor(r="Can not extend a lock which has not been yet acquired. Maybe a pending operation is in progress."){super(r)}};var F=class extends m{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 y=class extends R{};var w=class extends g{};import{v4 as kt}from"uuid";import st from"fs";import{resolve as ot}from"path";import{EventEmitter as bt}from"events";var it=(l,r,t)=>{if(l.length){let i=0,e=()=>{r(l[i],i,n=>{i+=1,n||i>=l.length?t(n):setTimeout(()=>e(),0)})};e()}else t()},et=(l,r,t)=>{let i=Object.keys(l);if(i.length){let e=0,n=()=>{let s=i[e];r(l[s],s,o=>{e+=1,o||e>=i.length?t(o):setTimeout(()=>n(),0)})};n()}else t()},ht=(l,r,t)=>{Array.isArray(l)?it(l,r,t):et(l,r,t)},mt=(l,r)=>{if(l.length){let t=0,i=(e,...n)=>{t+=1,e?r(e):t<l.length?setTimeout(()=>{n.length?l[t](...n,i):l[t](i)},0):n.length?r(null,n[0]):r()};l[t](i)}else r()},k={each:ht,eachIn:et,eachOf:it,waterfall:mt};import rt from"fs";import{resolve as nt}from"path";var S=class S{constructor(){this.isLoaded=!1;this.scripts=new Map,this.addScript("ZPOPRPUSH",rt.readFileSync(nt(__dirname,"./lua/zpoprpush.lua")).toString()),this.addScript("LPOPRPUSH",rt.readFileSync(nt(__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,o)=>{s?n(s):o?(e.id=o,n()):n(new b)})})),k.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 S.instance||(S.instance=new S),S.instance}};S.instance=null;var z=S;var pt=[4,0,0],v=class v extends bt{constructor(){super(...arguments);this.connectionClosed=!0}validateRedisVersion(t,i=0,e=0){if(!v.redisServerVersion)throw new u("UNKNOWN_REDIS_SERVER_VERSION");return v.redisServerVersion[0]>t||v.redisServerVersion[0]===t&&v.redisServerVersion[1]>=i&&v.redisServerVersion[2]>=e}validateRedisServerSupport(t){let i=e=>{let[n,s,o]=pt;this.validateRedisVersion(n,s,o)?e():e(new u("UNSUPPORTED_REDIS_SERVER_VERSION"))};v.redisServerVersion?i(t):this.updateServerVersion(e=>{e?t(e):i(t)})}sscanAll(t,i,e){let n=new Set,s=o=>{this.sscan(t,o,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=o=>{this.hscan(t,o,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){v.redisServerVersion?t():this.getInfo((i,e)=>{i?t(i):e?(v.redisServerVersion=e.split(`\r
`)[1].split(":")[1].split(".").map(n=>Number(n)),t()):t(new b)})}loadScripts(t){z.getInstance().loadScripts(this,t)}runScript(t,i,e,n){let s=z.getInstance().getScriptId(t);this.evalsha(s,[i.length,...i,...e],(o,a)=>{o?n(o):n(null,a)})}static addScript(t,i){if(!z.getInstance().addScript(t,i))throw new u(`A script with name [${t}] already exists`)}};v.redisServerVersion=null;var p=v;p.addScript("RELEASE_LOCK",st.readFileSync(ot(__dirname,"./lua/release-lock.lua")).toString());p.addScript("EXTEND_LOCK",st.readFileSync(ot(__dirname,"./lua/extend-lock.lua")).toString());var V=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=kt(),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 N)):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 F);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 E)):r(new x)}):r(new x)};t()}}extendLock(r){this.autoExtend?r(new O):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 O);else{let t=()=>{this.acquireLock(i=>{i?r(i):r(null,2)})};this.isLocked()?this.extend(i=>{i?i instanceof N?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 w("Can not switch state while another state transition is in progress.");return!1}if(r===this.isPowered){if(this.throwExceptionOnError)throw new w("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 w("Expected a pending state");this.isPowered=this.pendingState,this.pendingState=null}rollback(){if(this.pendingState===null)throw new w("Expected a pending state");this.pendingState=null}};import{EventEmitter as vt}from"events";var P=class extends vt{};var L=class extends P{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("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("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("down")):this.aborted&&this.powerManager.isDown()?this.emit("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 M("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 M("A timer is already running");this.powerManager.isGoingUp()&&this.powerManager.commit(),this.powerManager.isRunning()&&(this.interval=setInterval(()=>this.onTick(),this.time))}};var B=class{constructor(r,t=1e3){this.ticker=null;this.powerManager=null;this.getTicker=()=>{if(!this.ticker)throw new y("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 y("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("down",()=>{t.commit(),r()}),i.quit()}};this.managed=r,r||(this.ticker=new L(this.onTick,t),this.powerManager=new I)}getPowerManager(){if(!this.powerManager)throw new y("Expected an instance of PowerSwitch");return this.powerManager}};var $=class extends P{constructor(t,i,e,n){super();this.onTick=()=>{k.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 E?this.ticker.nextTick():this.emit("error",t)})};this.clearWorkerPool=t=>{this.workerPool.clear(t)};this.stopTicker=t=>{this.ticker.once("down",t),this.ticker.quit()};this.releaseLock=t=>{this.lock.releaseLock(t)};this.run=()=>{this.emit("up"),this.ticker.nextTick()};this.quit=t=>{k.waterfall([this.stopTicker,this.clearWorkerPool,this.releaseLock],()=>{this.emit("down"),t()})};this.powerManager=new I,this.redisClient=t,this.logger=n,this.lock=new V(t,i,6e4),this.ticker=new L(this.onTick),this.workerPool=e}addWorker(t){this.workerPool.add(t)}};var J=class{constructor(){this.pool=[];this.work=r=>{if(this.pool.length){let t=this.pool.map(i=>e=>i.work(e));k.waterfall(t,r)}else r()};this.add=r=>(this.pool.push(r),this.pool.length);this.clear=r=>{k.each(this.pool,(t,i,e)=>{t.quit(e)},()=>{this.pool=[],r()})}}};import{createLogger as Ct}from"bunyan";var D=()=>{},ft={debug:D,warn:D,info:D,error:D},C=null;function It(){C=null}function xt(l){if(C)throw new U("Logger has been already initialized.");C=l}function wt(l,r){var t;if(!l.enabled)return ft;if(C||(C=Ct(Y(H({},(t=l.options)!=null?t:{}),{name:"redis-smq"}))),r){let i=(e,n)=>(s,...o)=>{let a=typeof s=="string"?`${r} | ${s}`:s;return n[e](a,...o)};return{info:i("info",C),warn:i("warn",C),debug:i("debug",C),error:i("error",C)}}return C}var Tt={getLogger:wt,setLogger:xt,destroy:It};import{createClient as Rt}from"redis";var X=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 Et=function(l){return l?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.
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};
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.redis = exports.async = exports.logger = exports.WorkerPool = exports.WorkerRunner = exports.Worker = exports.Ticker = exports.RedisClient = exports.PowerSwitch = exports.Lock = void 0;
__exportStar(require("./types"), exports);
__exportStar(require("./src/errors"), exports);
__exportStar(require("./src/logger/errors"), exports);
__exportStar(require("./src/ticker/errors"), exports);
__exportStar(require("./src/lock/errors"), exports);
__exportStar(require("./src/redis-client/errors"), exports);
__exportStar(require("./src/worker/errors"), exports);
__exportStar(require("./src/power-switch/errors"), exports);
var lock_1 = require("./src/lock/lock");
Object.defineProperty(exports, "Lock", { enumerable: true, get: function () { return lock_1.Lock; } });
var power_switch_1 = require("./src/power-switch/power-switch");
Object.defineProperty(exports, "PowerSwitch", { enumerable: true, get: function () { return power_switch_1.PowerSwitch; } });
var redis_client_1 = require("./src/redis-client/redis-client");
Object.defineProperty(exports, "RedisClient", { enumerable: true, get: function () { return redis_client_1.RedisClient; } });
var ticker_1 = require("./src/ticker/ticker");
Object.defineProperty(exports, "Ticker", { enumerable: true, get: function () { return ticker_1.Ticker; } });
var worker_1 = require("./src/worker/worker");
Object.defineProperty(exports, "Worker", { enumerable: true, get: function () { return worker_1.Worker; } });
var worker_runner_1 = require("./src/worker/worker-runner/worker-runner");
Object.defineProperty(exports, "WorkerRunner", { enumerable: true, get: function () { return worker_runner_1.WorkerRunner; } });
var worker_pool_1 = require("./src/worker/worker-runner/worker-pool");
Object.defineProperty(exports, "WorkerPool", { enumerable: true, get: function () { return worker_pool_1.WorkerPool; } });
var logger_1 = require("./src/logger/logger");
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
var async_1 = require("./src/async/async");
Object.defineProperty(exports, "async", { enumerable: true, get: function () { return async_1.async; } });
var redis_client_2 = require("./src/redis-client");
Object.defineProperty(exports, "redis", { enumerable: true, get: function () { return redis_client_2.redis; } });
__exportStar(require("./src/event"), exports);
//# sourceMappingURL=index.js.map
{
"name": "redis-smq-common",
"version": "3.0.0-rc.7",
"version": "3.0.0-rc.8",
"description": "RedisSMQ Common Library provides many components that are mainly used by RedisSMQ and RedisSMQ Monitor.",

@@ -41,3 +41,2 @@ "author": "Weyoss <weyoss@protonmail.com>",

"@types/ioredis": "4.28.1",
"@types/redis": "2.8.32",
"bluebird": "3.7.2",

@@ -47,3 +46,2 @@ "bunyan": "1.8.15",

"lodash": "4.17.21",
"redis": "3.1.2",
"uuid": "8.3.2"

@@ -50,0 +48,0 @@ },

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc