redis-smq-common 1.0.0-rc.7 → 1.0.0

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/.codecov.yml ADDED
@@ -0,0 +1,5 @@
1
+ coverage:
2
+ status:
3
+ patch:
4
+ default:
5
+ target: 80%
package/CHANGELOG.md CHANGED
@@ -1,6 +1,32 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 1.0.0-rc.6 (2022-05-30)
3
+ ## 1.0.0 (20220-06-18)
4
+
5
+ * Rename logger/test00018 (f20fdf9)
6
+ * Test PowerManager (8d6f5e6)
7
+ * Complete async tests to reach 9x% code coverage (ea57f8f)
8
+ * Test async.waterfall() (ae4a283)
9
+ * Increase code coverage (c5e3f2b)
10
+
11
+ ## 1.0.0-rc.11 (2022-05-31)
12
+
13
+ * Update RedisClient and IRedisClientMulti interfaces (8732c97)
14
+
15
+ ## 1.0.0-rc.10 (2022-05-31)
16
+
17
+ * Fix broken promisify(All) because of ICallback typing (4250e32)
18
+
19
+ ## 1.0.0-rc.9 (2022-05-31)
20
+
21
+ * Improve RedisClient typings (27219a6)
22
+ * Set up codecov (98293bd)
23
+ * Fix type coverage (2f4a722)
24
+
25
+ ## 1.0.0-rc.8 (2022-05-30)
26
+
27
+ * Add WatchedKeysChangedError class (1e42e80)
28
+
29
+ ## 1.0.0-rc.7 (2022-05-30)
4
30
 
5
31
  * Fix various redis errors (9349261)
6
32
 
@@ -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;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IoredisClientMulti = void 0;
4
4
  const redis_client_error_1 = require("../errors/redis-client.error");
5
+ const watched_keys_changed_error_1 = require("../errors/watched-keys-changed.error");
5
6
  class IoredisClientMulti {
6
7
  constructor(client) {
7
8
  this.multi = client.multi();
@@ -35,7 +36,7 @@ class IoredisClientMulti {
35
36
  return this;
36
37
  }
37
38
  zrem(key, element) {
38
- this.multi.zrem(key, element);
39
+ this.multi.zrem(key, ...(typeof element === 'string' ? [element] : element));
39
40
  return this;
40
41
  }
41
42
  sadd(key, element) {
@@ -51,13 +52,21 @@ class IoredisClientMulti {
51
52
  return this;
52
53
  }
53
54
  hdel(key, field) {
54
- 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);
55
60
  return this;
56
61
  }
57
62
  pexpire(key, millis) {
58
63
  this.multi.pexpire(key, millis);
59
64
  return this;
60
65
  }
66
+ expire(key, secs) {
67
+ this.multi.expire(key, secs);
68
+ return this;
69
+ }
61
70
  rpoplpush(source, destination) {
62
71
  this.multi.rpoplpush(source, destination);
63
72
  return this;
@@ -71,7 +80,7 @@ class IoredisClientMulti {
71
80
  if (err)
72
81
  cb(err);
73
82
  else if (!reply)
74
- cb(new redis_client_error_1.RedisClientError(`Redis transaction has been abandoned. Try again.`));
83
+ cb(new watched_keys_changed_error_1.WatchedKeysChangedError());
75
84
  else {
76
85
  const lengths = [];
77
86
  let err = null;
@@ -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;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeRedisV3ClientMulti = void 0;
4
- const redis_client_error_1 = require("../errors/redis-client.error");
4
+ const watched_keys_changed_error_1 = require("../errors/watched-keys-changed.error");
5
5
  class NodeRedisV3ClientMulti {
6
6
  constructor(client) {
7
7
  this.multi = client.multi();
@@ -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;
@@ -71,7 +79,7 @@ class NodeRedisV3ClientMulti {
71
79
  if (err)
72
80
  cb(err);
73
81
  else if (!reply)
74
- cb(new redis_client_error_1.RedisClientError(`Redis transaction has been abandoned. Try again.`));
82
+ cb(new watched_keys_changed_error_1.WatchedKeysChangedError());
75
83
  else
76
84
  cb(null, reply);
77
85
  });
@@ -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;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeRedisV4ClientMulti = void 0;
4
+ const client_1 = require("@redis/client");
5
+ const watched_keys_changed_error_1 = require("../errors/watched-keys-changed.error");
4
6
  class NodeRedisV4ClientMulti {
5
7
  constructor(client) {
6
8
  this.multi = client.multi();
@@ -53,10 +55,18 @@ class NodeRedisV4ClientMulti {
53
55
  this.multi.hDel(key, field);
54
56
  return this;
55
57
  }
58
+ hincrby(key, field, by) {
59
+ this.multi.hIncrBy(key, field, by);
60
+ return this;
61
+ }
56
62
  pexpire(key, millis) {
57
63
  this.multi.pExpire(key, millis);
58
64
  return this;
59
65
  }
66
+ expire(key, secs) {
67
+ this.multi.expire(key, secs);
68
+ return this;
69
+ }
60
70
  rpoplpush(source, destination) {
61
71
  this.multi.rPopLPush(source, destination);
62
72
  return this;
@@ -69,7 +79,12 @@ class NodeRedisV4ClientMulti {
69
79
  this.multi
70
80
  .exec()
71
81
  .then((reply) => cb(null, reply))
72
- .catch(cb);
82
+ .catch((err) => {
83
+ if (err instanceof client_1.WatchError)
84
+ cb(new watched_keys_changed_error_1.WatchedKeysChangedError());
85
+ else
86
+ cb(err);
87
+ });
73
88
  }
74
89
  }
75
90
  exports.NodeRedisV4ClientMulti = NodeRedisV4ClientMulti;
@@ -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) {
@@ -0,0 +1,4 @@
1
+ import { RedisClientError } from './redis-client.error';
2
+ export declare class WatchedKeysChangedError extends RedisClientError {
3
+ constructor(msg?: string);
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WatchedKeysChangedError = void 0;
4
+ const redis_client_error_1 = require("./redis-client.error");
5
+ class WatchedKeysChangedError extends redis_client_error_1.RedisClientError {
6
+ constructor(msg = 'One (or more) of the watched keys has been changed') {
7
+ super(msg);
8
+ }
9
+ }
10
+ exports.WatchedKeysChangedError = WatchedKeysChangedError;
11
+ //# sourceMappingURL=watched-keys-changed.error.js.map
@@ -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
  }
@@ -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.7",
3
+ "version": "1.0.0",
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",