redis-smq-common 1.0.0-rc.8 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/.codecov.yml +5 -0
  2. package/CHANGELOG.md +29 -0
  3. package/dist/src/async/async.js +8 -6
  4. package/dist/src/redis-client/clients/ioredis-client-multi.d.ts +4 -2
  5. package/dist/src/redis-client/clients/ioredis-client-multi.js +10 -2
  6. package/dist/src/redis-client/clients/ioredis-client.d.ts +9 -7
  7. package/dist/src/redis-client/clients/ioredis-client.js +6 -0
  8. package/dist/src/redis-client/clients/node-redis-v3-client-multi.d.ts +4 -2
  9. package/dist/src/redis-client/clients/node-redis-v3-client-multi.js +8 -0
  10. package/dist/src/redis-client/clients/node-redis-v3-client.d.ts +9 -7
  11. package/dist/src/redis-client/clients/node-redis-v3-client.js +6 -0
  12. package/dist/src/redis-client/clients/node-redis-v4-client-multi.d.ts +4 -2
  13. package/dist/src/redis-client/clients/node-redis-v4-client-multi.js +8 -0
  14. package/dist/src/redis-client/clients/node-redis-v4-client.d.ts +9 -7
  15. package/dist/src/redis-client/clients/node-redis-v4-client.js +10 -2
  16. package/dist/src/redis-client/redis-client.d.ts +12 -10
  17. package/dist/src/redis-client/redis-client.js +3 -9
  18. package/dist/src/worker/worker-error.d.ts +3 -0
  19. package/dist/src/worker/worker-error.js +8 -0
  20. package/dist/src/worker/worker-runner/worker-pool.d.ts +0 -2
  21. package/dist/src/worker/worker-runner/worker-pool.js +3 -15
  22. package/dist/src/worker/worker.js +4 -4
  23. package/dist/types/index.d.ts +6 -4
  24. package/package.json +1 -1
  25. package/dist/src/worker/worker-runner/worker-runner.error.d.ts +0 -3
  26. package/dist/src/worker/worker-runner/worker-runner.error.js +0 -8
package/.codecov.yml ADDED
@@ -0,0 +1,5 @@
1
+ coverage:
2
+ status:
3
+ patch:
4
+ default:
5
+ target: 80%
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.1 (2022-07-07)
4
+
5
+ * Remove unused WorkerRunnerError (48e7206)
6
+ * Use namespaced WorkerError (517224c)
7
+ * Make array looping asynchronous (cd66e51)
8
+ * Run workers one by one without a delay (099b488)
9
+
10
+ ## 1.0.0 (20220-06-18)
11
+
12
+ * Rename logger/test00018 (f20fdf9)
13
+ * Test PowerManager (8d6f5e6)
14
+ * Complete async tests to reach 9x% code coverage (ea57f8f)
15
+ * Test async.waterfall() (ae4a283)
16
+ * Increase code coverage (c5e3f2b)
17
+
18
+ ## 1.0.0-rc.11 (2022-05-31)
19
+
20
+ * Update RedisClient and IRedisClientMulti interfaces (8732c97)
21
+
22
+ ## 1.0.0-rc.10 (2022-05-31)
23
+
24
+ * Fix broken promisify(All) because of ICallback typing (4250e32)
25
+
26
+ ## 1.0.0-rc.9 (2022-05-31)
27
+
28
+ * Improve RedisClient typings (27219a6)
29
+ * Set up codecov (98293bd)
30
+ * Fix type coverage (2f4a722)
31
+
3
32
  ## 1.0.0-rc.8 (2022-05-30)
4
33
 
5
34
  * Add WatchedKeysChangedError class (1e42e80)
@@ -10,7 +10,7 @@ const eachOf = (collection, iteratee, callback) => {
10
10
  if (err || idx >= collection.length)
11
11
  callback(err);
12
12
  else
13
- iterate();
13
+ setTimeout(() => iterate(), 0);
14
14
  });
15
15
  };
16
16
  iterate();
@@ -30,7 +30,7 @@ const eachIn = (collection, iteratee, callback) => {
30
30
  if (err || idx >= keys.length)
31
31
  callback(err);
32
32
  else
33
- iterate();
33
+ setTimeout(() => iterate(), 0);
34
34
  });
35
35
  };
36
36
  iterate();
@@ -53,10 +53,12 @@ const waterfall = (tasks, callback) => {
53
53
  callback(err);
54
54
  }
55
55
  else if (idx < tasks.length) {
56
- if (args.length)
57
- tasks[idx](...args, exec);
58
- else
59
- tasks[idx](exec);
56
+ setTimeout(() => {
57
+ if (args.length)
58
+ tasks[idx](...args, exec);
59
+ else
60
+ tasks[idx](exec);
61
+ }, 0);
60
62
  }
61
63
  else if (args.length) {
62
64
  callback(null, args[0]);
@@ -10,12 +10,14 @@ export declare class IoredisClientMulti implements IRedisClientMulti {
10
10
  rpop(key: string): this;
11
11
  rpush(key: string, element: string): this;
12
12
  zadd(key: string, score: number, element: string): this;
13
- zrem(key: string, element: string): this;
13
+ zrem(key: string, element: string | string[]): this;
14
14
  sadd(key: string, element: string): this;
15
15
  srem(key: string, element: string | string[]): this;
16
16
  hset(key: string, field: string, value: string): this;
17
- hdel(key: string, field: string): this;
17
+ hdel(key: string, field: string | string[]): this;
18
+ hincrby(key: string, field: string, by: number): this;
18
19
  pexpire(key: string, millis: number): this;
20
+ expire(key: string, secs: number): this;
19
21
  rpoplpush(source: string, destination: string): this;
20
22
  del(key: string | string[]): this;
21
23
  exec(cb: ICallback<unknown[]>): void;
@@ -36,7 +36,7 @@ class IoredisClientMulti {
36
36
  return this;
37
37
  }
38
38
  zrem(key, element) {
39
- this.multi.zrem(key, element);
39
+ this.multi.zrem(key, ...(typeof element === 'string' ? [element] : element));
40
40
  return this;
41
41
  }
42
42
  sadd(key, element) {
@@ -52,13 +52,21 @@ class IoredisClientMulti {
52
52
  return this;
53
53
  }
54
54
  hdel(key, field) {
55
- this.multi.hdel(key, field);
55
+ this.multi.hdel(key, ...(typeof field === 'string' ? [field] : field));
56
+ return this;
57
+ }
58
+ hincrby(key, field, by) {
59
+ this.multi.hincrby(key, field, by);
56
60
  return this;
57
61
  }
58
62
  pexpire(key, millis) {
59
63
  this.multi.pexpire(key, millis);
60
64
  return this;
61
65
  }
66
+ expire(key, secs) {
67
+ this.multi.expire(key, secs);
68
+ return this;
69
+ }
62
70
  rpoplpush(source, destination) {
63
71
  this.multi.rpoplpush(source, destination);
64
72
  return this;
@@ -11,7 +11,7 @@ export declare class IoredisClient extends RedisClient {
11
11
  value: number;
12
12
  };
13
13
  exists?: 'NX' | 'XX';
14
- }, cb: ICallback<string>): void;
14
+ }, cb: ICallback<string | null>): void;
15
15
  zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
16
16
  multi(): IoredisClientMulti;
17
17
  watch(args: string[], cb: ICallback<string>): void;
@@ -21,29 +21,31 @@ export declare class IoredisClient extends RedisClient {
21
21
  zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
22
22
  psubscribe(pattern: string): void;
23
23
  punsubscribe(channel: string): void;
24
+ subscribe(channel: string): void;
25
+ unsubscribe(channel: string): void;
24
26
  zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
25
27
  smembers(key: string, cb: ICallback<string[]>): void;
26
28
  sadd(key: string, member: string, cb: ICallback<number>): void;
27
29
  hgetall(key: string, cb: ICallback<Record<string, string>>): void;
28
- hget(key: string, field: string, cb: ICallback<string>): void;
30
+ hget(key: string, field: string, cb: ICallback<string | null>): void;
29
31
  hset(key: string, field: string, value: string, cb: ICallback<number>): void;
30
32
  hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
31
33
  lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
32
34
  hkeys(key: string, cb: ICallback<string[]>): void;
33
35
  hlen(key: string, cb: ICallback<number>): void;
34
- brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string>): void;
35
- rpoplpush(source: string, destination: string, cb: ICallback<string>): void;
36
+ brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
37
+ rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
36
38
  zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
37
- rpop(key: string, cb: ICallback<string>): void;
39
+ rpop(key: string, cb: ICallback<string | null>): void;
38
40
  lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
39
41
  publish(channel: string, message: string, cb: ICallback<number>): void;
40
42
  flushall(cb: ICallback<string>): void;
41
43
  loadScript(script: string, cb: ICallback<string>): void;
42
44
  evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
43
- get(key: string, cb: ICallback<string>): void;
45
+ get(key: string, cb: ICallback<string | null>): void;
44
46
  del(key: string | string[], cb: ICallback<number>): void;
45
47
  llen(key: string, cb: ICallback<number>): void;
46
- lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
48
+ lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
47
49
  zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
48
50
  hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
49
51
  halt(cb: ICallback<void>): void;
@@ -59,6 +59,12 @@ class IoredisClient extends redis_client_1.RedisClient {
59
59
  punsubscribe(channel) {
60
60
  this.client.punsubscribe(channel);
61
61
  }
62
+ subscribe(channel) {
63
+ this.client.subscribe(channel);
64
+ }
65
+ unsubscribe(channel) {
66
+ this.client.unsubscribe(channel);
67
+ }
62
68
  zrangebyscore(key, min, max, cb) {
63
69
  this.client.zrangebyscore(key, min, max, cb);
64
70
  }
@@ -10,12 +10,14 @@ export declare class NodeRedisV3ClientMulti implements IRedisClientMulti {
10
10
  rpop(key: string): this;
11
11
  rpush(key: string, element: string): this;
12
12
  zadd(key: string, score: number, element: string): this;
13
- zrem(key: string, element: string): this;
13
+ zrem(key: string, element: string | string[]): this;
14
14
  sadd(key: string, element: string): this;
15
15
  srem(key: string, element: string | string[]): this;
16
16
  hset(key: string, field: string, value: string): this;
17
- hdel(key: string, field: string): this;
17
+ hdel(key: string, field: string | string[]): this;
18
+ hincrby(key: string, field: string, by: number): this;
18
19
  pexpire(key: string, millis: number): this;
20
+ expire(key: string, secs: number): this;
19
21
  rpoplpush(source: string, destination: string): this;
20
22
  del(key: string | string[]): this;
21
23
  exec(cb: ICallback<unknown[]>): void;
@@ -54,10 +54,18 @@ class NodeRedisV3ClientMulti {
54
54
  this.multi.hdel(key, field);
55
55
  return this;
56
56
  }
57
+ hincrby(key, field, by) {
58
+ this.multi.hincrby(key, field, by);
59
+ return this;
60
+ }
57
61
  pexpire(key, millis) {
58
62
  this.multi.pexpire(key, millis);
59
63
  return this;
60
64
  }
65
+ expire(key, secs) {
66
+ this.multi.expire(key, secs);
67
+ return this;
68
+ }
61
69
  rpoplpush(source, destination) {
62
70
  this.multi.rpoplpush(source, destination);
63
71
  return this;
@@ -11,7 +11,7 @@ export declare class NodeRedisV3Client extends RedisClient {
11
11
  value: number;
12
12
  };
13
13
  exists?: 'NX' | 'XX';
14
- }, cb: ICallback<string>): void;
14
+ }, cb: ICallback<string | null>): void;
15
15
  zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
16
16
  multi(): NodeRedisV3ClientMulti;
17
17
  watch(args: string[], cb: ICallback<string>): void;
@@ -21,29 +21,31 @@ export declare class NodeRedisV3Client extends RedisClient {
21
21
  zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
22
22
  psubscribe(pattern: string): void;
23
23
  punsubscribe(channel: string): void;
24
+ subscribe(channel: string): void;
25
+ unsubscribe(channel: string): void;
24
26
  zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
25
27
  smembers(key: string, cb: ICallback<string[]>): void;
26
28
  sadd(key: string, member: string, cb: ICallback<number>): void;
27
29
  hgetall(key: string, cb: ICallback<Record<string, string>>): void;
28
- hget(key: string, field: string, cb: ICallback<string>): void;
30
+ hget(key: string, field: string, cb: ICallback<string | null>): void;
29
31
  hset(key: string, field: string, value: string, cb: ICallback<number>): void;
30
32
  hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
31
33
  lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
32
34
  hkeys(key: string, cb: ICallback<string[]>): void;
33
35
  hlen(key: string, cb: ICallback<number>): void;
34
- brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string>): void;
35
- rpoplpush(source: string, destination: string, cb: ICallback<string>): void;
36
+ brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
37
+ rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
36
38
  zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
37
- rpop(key: string, cb: ICallback<string>): void;
39
+ rpop(key: string, cb: ICallback<string | null>): void;
38
40
  lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
39
41
  publish(channel: string, message: string, cb: ICallback<number>): void;
40
42
  flushall(cb: ICallback<string>): void;
41
43
  loadScript(script: string, cb: ICallback<string>): void;
42
44
  evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
43
- get(key: string, cb: ICallback<string>): void;
45
+ get(key: string, cb: ICallback<string | null>): void;
44
46
  del(key: string | string[], cb: ICallback<number>): void;
45
47
  llen(key: string, cb: ICallback<number>): void;
46
- lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
48
+ lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
47
49
  zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
48
50
  hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
49
51
  halt(cb: ICallback<void>): void;
@@ -86,6 +86,12 @@ class NodeRedisV3Client extends redis_client_1.RedisClient {
86
86
  punsubscribe(channel) {
87
87
  this.client.punsubscribe(channel);
88
88
  }
89
+ subscribe(channel) {
90
+ this.client.subscribe(channel);
91
+ }
92
+ unsubscribe(channel) {
93
+ this.client.unsubscribe(channel);
94
+ }
89
95
  zrangebyscore(key, min, max, cb) {
90
96
  this.client.zrangebyscore(key, min, max, cb);
91
97
  }
@@ -9,12 +9,14 @@ export declare class NodeRedisV4ClientMulti implements IRedisClientMulti {
9
9
  rpop(key: string): this;
10
10
  rpush(key: string, element: string): this;
11
11
  zadd(key: string, score: number, element: string): this;
12
- zrem(key: string, element: string): this;
12
+ zrem(key: string, element: string | string[]): this;
13
13
  sadd(key: string, element: string): this;
14
14
  srem(key: string, element: string | string[]): this;
15
15
  hset(key: string, field: string, value: string): this;
16
- hdel(key: string, field: string): this;
16
+ hdel(key: string, field: string | string[]): this;
17
+ hincrby(key: string, field: string, by: number): this;
17
18
  pexpire(key: string, millis: number): this;
19
+ expire(key: string, secs: number): this;
18
20
  rpoplpush(source: string, destination: string): this;
19
21
  del(key: string | string[]): this;
20
22
  exec(cb: ICallback<unknown[]>): void;
@@ -55,10 +55,18 @@ class NodeRedisV4ClientMulti {
55
55
  this.multi.hDel(key, field);
56
56
  return this;
57
57
  }
58
+ hincrby(key, field, by) {
59
+ this.multi.hIncrBy(key, field, by);
60
+ return this;
61
+ }
58
62
  pexpire(key, millis) {
59
63
  this.multi.pExpire(key, millis);
60
64
  return this;
61
65
  }
66
+ expire(key, secs) {
67
+ this.multi.expire(key, secs);
68
+ return this;
69
+ }
62
70
  rpoplpush(source, destination) {
63
71
  this.multi.rPopLPush(source, destination);
64
72
  return this;
@@ -11,7 +11,7 @@ export declare class NodeRedisV4Client extends RedisClient {
11
11
  value: number;
12
12
  };
13
13
  exists?: 'NX' | 'XX';
14
- }, cb: ICallback<string>): void;
14
+ }, cb: ICallback<string | null>): void;
15
15
  zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
16
16
  multi(): NodeRedisV4ClientMulti;
17
17
  watch(args: string[], cb: ICallback<string>): void;
@@ -21,29 +21,31 @@ export declare class NodeRedisV4Client extends RedisClient {
21
21
  zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
22
22
  psubscribe(pattern: string): void;
23
23
  punsubscribe(channel: string): void;
24
+ subscribe(channel: string): void;
25
+ unsubscribe(channel: string): void;
24
26
  zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
25
27
  smembers(key: string, cb: ICallback<string[]>): void;
26
28
  sadd(key: string, member: string, cb: ICallback<number>): void;
27
29
  hgetall(key: string, cb: ICallback<Record<string, string>>): void;
28
- hget(key: string, field: string, cb: ICallback<string>): void;
30
+ hget(key: string, field: string, cb: ICallback<string | null>): void;
29
31
  hset(key: string, field: string, value: string, cb: ICallback<number>): void;
30
32
  hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
31
33
  lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
32
34
  hkeys(key: string, cb: ICallback<string[]>): void;
33
35
  hlen(key: string, cb: ICallback<number>): void;
34
- brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string>): void;
35
- rpoplpush(source: string, destination: string, cb: ICallback<string>): void;
36
+ brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
37
+ rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
36
38
  zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
37
- rpop(key: string, cb: ICallback<string>): void;
39
+ rpop(key: string, cb: ICallback<string | null>): void;
38
40
  lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
39
41
  publish(channel: string, message: string, cb: ICallback<number>): void;
40
42
  flushall(cb: ICallback<string>): void;
41
43
  loadScript(script: string, cb: ICallback<string>): void;
42
44
  evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
43
- get(key: string, cb: ICallback<string>): void;
45
+ get(key: string, cb: ICallback<string | null>): void;
44
46
  del(key: string | string[], cb: ICallback<number>): void;
45
47
  llen(key: string, cb: ICallback<number>): void;
46
- lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
48
+ lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
47
49
  zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
48
50
  hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
49
51
  halt(cb: ICallback<void>): void;
@@ -74,6 +74,14 @@ class NodeRedisV4Client extends redis_client_1.RedisClient {
74
74
  punsubscribe(channel) {
75
75
  this.client.pUnsubscribe(channel).catch(() => void 0);
76
76
  }
77
+ subscribe(channel) {
78
+ this.client.subscribe(channel, (message, channel) => {
79
+ this.client.emit('message', channel, message);
80
+ });
81
+ }
82
+ unsubscribe(channel) {
83
+ this.client.unsubscribe(channel).catch(() => void 0);
84
+ }
77
85
  zrangebyscore(key, min, max, cb) {
78
86
  this.client
79
87
  .zRangeByScore(key, min, max)
@@ -101,7 +109,7 @@ class NodeRedisV4Client extends redis_client_1.RedisClient {
101
109
  hget(key, field, cb) {
102
110
  this.client
103
111
  .hGet(key, field)
104
- .then((reply) => cb(null, reply))
112
+ .then((reply) => cb(null, reply !== null && reply !== void 0 ? reply : null))
105
113
  .catch(cb);
106
114
  }
107
115
  hset(key, field, value, cb) {
@@ -179,7 +187,7 @@ class NodeRedisV4Client extends redis_client_1.RedisClient {
179
187
  flushall(cb) {
180
188
  this.client
181
189
  .flushAll()
182
- .then(() => cb())
190
+ .then((reply) => cb(null, reply))
183
191
  .catch(cb);
184
192
  }
185
193
  loadScript(script, cb) {
@@ -19,7 +19,7 @@ export declare abstract class RedisClient extends EventEmitter {
19
19
  value: number;
20
20
  };
21
21
  exists?: 'NX' | 'XX';
22
- }, cb: ICallback<string>): void;
22
+ }, cb: ICallback<string | null>): void;
23
23
  abstract zadd(key: string, score: number, member: string, cb: ICallback<number | string>): void;
24
24
  abstract multi(): IRedisClientMulti;
25
25
  abstract watch(args: string[], cb: ICallback<string>): void;
@@ -29,32 +29,34 @@ export declare abstract class RedisClient extends EventEmitter {
29
29
  abstract zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
30
30
  abstract psubscribe(pattern: string): void;
31
31
  abstract punsubscribe(channel: string): void;
32
+ abstract subscribe(channel: string): void;
33
+ abstract unsubscribe(channel: string): void;
32
34
  abstract zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
33
35
  abstract smembers(key: string, cb: ICallback<string[]>): void;
34
36
  abstract sadd(key: string, member: string, cb: ICallback<number>): void;
35
37
  abstract hgetall(key: string, cb: ICallback<Record<string, string>>): void;
36
- abstract hget(key: string, field: string, cb: ICallback<string>): void;
38
+ abstract hget(key: string, field: string, cb: ICallback<string | null>): void;
37
39
  abstract hset(key: string, field: string, value: string, cb: ICallback<number>): void;
38
40
  abstract hdel(key: string, fields: string | string[], cb: ICallback<number>): void;
39
41
  abstract lrange(key: string, start: number, stop: number, cb: ICallback<string[]>): void;
40
42
  abstract hkeys(key: string, cb: ICallback<string[]>): void;
41
43
  abstract hlen(key: string, cb: ICallback<number>): void;
42
- abstract brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string>): void;
43
- abstract rpoplpush(source: string, destination: string, cb: ICallback<string>): void;
44
- zpophgetrpush(source: string, sourceHash: string, destination: string, cb: ICallback<string>): void;
45
- lpoprpushextra(source: string, destination: string, listSize: number, expire: number, cb: ICallback<string>): void;
46
- lpoprpush(source: string, destination: string, cb: ICallback<string>): void;
44
+ abstract brpoplpush(source: string, destination: string, timeout: number, cb: ICallback<string | null>): void;
45
+ abstract rpoplpush(source: string, destination: string, cb: ICallback<string | null>): void;
46
+ zpophgetrpush(source: string, sourceHash: string, destination: string, cb: ICallback<string | null>): void;
47
+ lpoprpushextra(source: string, destination: string, listSize: number, expire: number, cb: ICallback<string | null>): void;
48
+ lpoprpush(source: string, destination: string, cb: ICallback<string | null>): void;
47
49
  abstract zrangebyscorewithscores(source: string, min: number, max: number, cb: ICallback<Record<string, string>>): void;
48
- abstract rpop(key: string, cb: ICallback<string>): void;
50
+ abstract rpop(key: string, cb: ICallback<string | null>): void;
49
51
  abstract lrem(key: string, count: number, element: string, cb: ICallback<number>): void;
50
52
  abstract publish(channel: string, message: string, cb: ICallback<number>): void;
51
53
  abstract flushall(cb: ICallback<string>): void;
52
54
  abstract loadScript(script: string, cb: ICallback<string>): void;
53
55
  abstract evalsha(hash: string, args: (string | number)[] | string | number, cb: (err?: Error | null, res?: unknown) => void): void;
54
- abstract get(key: string, cb: ICallback<string>): void;
56
+ abstract get(key: string, cb: ICallback<string | null>): void;
55
57
  abstract del(key: string | string[], cb: ICallback<number>): void;
56
58
  abstract llen(key: string, cb: ICallback<number>): void;
57
- abstract lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string>): void;
59
+ abstract lmove(source: string, destination: string, from: 'LEFT' | 'RIGHT', to: 'LEFT' | 'RIGHT', cb: ICallback<string | null>): void;
58
60
  abstract zremrangebyscore(source: string, min: number | string, max: number | string, cb: ICallback<number>): void;
59
61
  abstract hmget(source: string, keys: string[], cb: ICallback<(string | null)[]>): void;
60
62
  abstract halt(cb: ICallback<void>): void;
@@ -29,20 +29,16 @@ class RedisClient extends events_1.EventEmitter {
29
29
  this.runScript(ELuaScriptName.ZPOPHGETRPUSH, [source, sourceHash, destination], [], (err, res) => {
30
30
  if (err)
31
31
  cb(err);
32
- else if (typeof res !== 'string')
33
- cb();
34
32
  else
35
- cb(null, res);
33
+ cb(null, typeof res === 'string' ? res : null);
36
34
  });
37
35
  }
38
36
  lpoprpushextra(source, destination, listSize, expire, cb) {
39
37
  this.runScript(ELuaScriptName.LPOPRPUSHEXTRA, [source, destination], [listSize, expire], (err, res) => {
40
38
  if (err)
41
39
  cb(err);
42
- else if (typeof res !== 'string')
43
- cb();
44
40
  else
45
- cb(null, res);
41
+ cb(null, typeof res === 'string' ? res : null);
46
42
  });
47
43
  }
48
44
  lpoprpush(source, destination, cb) {
@@ -53,10 +49,8 @@ class RedisClient extends events_1.EventEmitter {
53
49
  this.runScript(ELuaScriptName.LPOPRPUSH, [source, destination], [], (err, res) => {
54
50
  if (err)
55
51
  cb(err);
56
- else if (typeof res !== 'string')
57
- cb();
58
52
  else
59
- cb(null, res);
53
+ cb(null, typeof res === 'string' ? res : null);
60
54
  });
61
55
  }
62
56
  }
@@ -0,0 +1,3 @@
1
+ import { PanicError } from '../errors/panic.error';
2
+ export declare class WorkerError extends PanicError {
3
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkerError = void 0;
4
+ const panic_error_1 = require("../errors/panic.error");
5
+ class WorkerError extends panic_error_1.PanicError {
6
+ }
7
+ exports.WorkerError = WorkerError;
8
+ //# sourceMappingURL=worker-error.js.map
@@ -2,8 +2,6 @@ import { Worker } from '../worker';
2
2
  import { ICallback } from '../../../types';
3
3
  export declare class WorkerPool {
4
4
  private pool;
5
- private index;
6
- private getCurrentPoolItem;
7
5
  work: (cb: ICallback<void>) => void;
8
6
  add: (worker: Worker) => number;
9
7
  clear: (cb: ICallback<void>) => void;
@@ -5,22 +5,11 @@ const async_1 = require("../../async/async");
5
5
  class WorkerPool {
6
6
  constructor() {
7
7
  this.pool = [];
8
- this.index = 0;
9
- this.getCurrentPoolItem = () => {
8
+ this.work = (cb) => {
10
9
  if (this.pool.length) {
11
- const worker = this.pool[this.index];
12
- this.index += 1;
13
- if (this.index >= this.pool.length) {
14
- this.index = 0;
15
- }
16
- return worker;
10
+ const tasks = this.pool.map((worker) => (cb) => worker.work(cb));
11
+ async_1.async.waterfall(tasks, cb);
17
12
  }
18
- return null;
19
- };
20
- this.work = (cb) => {
21
- const worker = this.getCurrentPoolItem();
22
- if (worker)
23
- worker.work(cb);
24
13
  else
25
14
  cb();
26
15
  };
@@ -33,7 +22,6 @@ class WorkerPool {
33
22
  worker.quit(done);
34
23
  }, () => {
35
24
  this.pool = [];
36
- this.index = 0;
37
25
  cb();
38
26
  });
39
27
  };
@@ -4,14 +4,14 @@ exports.Worker = void 0;
4
4
  const ticker_1 = require("../ticker/ticker");
5
5
  const events_1 = require("../events/events");
6
6
  const power_manager_1 = require("../power-manager/power-manager");
7
- const panic_error_1 = require("../errors/panic.error");
7
+ const worker_error_1 = require("./worker-error");
8
8
  class Worker {
9
9
  constructor(managed, timeout = 1000) {
10
10
  this.ticker = null;
11
11
  this.powerManager = null;
12
12
  this.getTicker = () => {
13
13
  if (!this.ticker) {
14
- throw new panic_error_1.PanicError(`Expected an instance of Ticker`);
14
+ throw new worker_error_1.WorkerError(`Expected an instance of Ticker`);
15
15
  }
16
16
  return this.ticker;
17
17
  };
@@ -24,7 +24,7 @@ class Worker {
24
24
  };
25
25
  this.run = () => {
26
26
  if (this.managed) {
27
- throw new panic_error_1.PanicError('You can not run a managed worker');
27
+ throw new worker_error_1.WorkerError('You can not run a managed worker');
28
28
  }
29
29
  const powerManager = this.getPowerManager();
30
30
  powerManager.goingUp();
@@ -54,7 +54,7 @@ class Worker {
54
54
  }
55
55
  getPowerManager() {
56
56
  if (!this.powerManager) {
57
- throw new panic_error_1.PanicError('Expected an instance of PowerManager');
57
+ throw new worker_error_1.WorkerError('Expected an instance of PowerManager');
58
58
  }
59
59
  return this.powerManager;
60
60
  }
@@ -29,14 +29,16 @@ export interface IRedisClientMulti {
29
29
  rpush(key: string, element: string): this;
30
30
  rpop(key: string): this;
31
31
  lpush(key: string, element: string): this;
32
- hdel(key: string, field: string): this;
32
+ hdel(key: string, field: string | string[]): this;
33
+ hincrby(key: string, field: string, by: number): this;
33
34
  del(key: string | string[]): this;
34
35
  srem(key: string, element: string | string[]): this;
35
36
  sadd(key: string, element: string): this;
36
- zrem(key: string, element: string): this;
37
+ zrem(key: string, element: string | string[]): this;
37
38
  zadd(key: string, score: number, element: string): this;
38
39
  hset(key: string, field: string, value: string): this;
39
40
  pexpire(key: string, millis: number): this;
41
+ expire(key: string, secs: number): this;
40
42
  ltrim(key: string, start: number, stop: number): this;
41
43
  rpoplpush(source: string, destination: string): this;
42
44
  exec(cb: ICallback<unknown[]>): void;
@@ -56,8 +58,8 @@ declare module 'ioredis' {
56
58
  }
57
59
  }
58
60
  export interface ICallback<T> {
59
- (err?: Error | null, reply?: T | null): void;
60
- (err: null | undefined, reply: T): void;
61
+ (err?: Error | null, reply?: T): void;
62
+ (err: undefined | null, reply: T): void;
61
63
  }
62
64
  export declare type TFunction<TReturn = void, TArgs = any> = (...args: TArgs[]) => TReturn;
63
65
  export declare type TUnaryFunction<T, E = void> = (reply: T) => E;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redis-smq-common",
3
- "version": "1.0.0-rc.8",
3
+ "version": "1.0.1",
4
4
  "description": "RedisSMQ shared components that may be used by integrated applications and extensions.",
5
5
  "author": "Weyoss <weyoss@protonmail.com>",
6
6
  "license": "MIT",
@@ -1,3 +0,0 @@
1
- import { RedisSMQError } from '../../errors/redis-smq.error';
2
- export declare class WorkerRunnerError extends RedisSMQError {
3
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkerRunnerError = void 0;
4
- const redis_smq_error_1 = require("../../errors/redis-smq.error");
5
- class WorkerRunnerError extends redis_smq_error_1.RedisSMQError {
6
- }
7
- exports.WorkerRunnerError = WorkerRunnerError;
8
- //# sourceMappingURL=worker-runner.error.js.map