redis-smq-common 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 1.0.3 (2022-08-16)
4
+
5
+ * [RedisClient] Update tests (6f1fd51)
6
+ * [RedisClient] Make validateRedisVersion() public (c2fccb3)
7
+ * [RedisClient] Support MATCH and COUNT options for sscan (12b24ac)
8
+ * [RedisClient] Fallback to smembers when sscan is not supported (8a4409f)
9
+ * [RedisClient] Test sscan command (17b8279)
10
+ * [RedisClient] Add sscan command (b771873)
11
+
3
12
  ## 1.0.2 (2022-08-10)
4
13
 
5
14
  * Update LockManager tests (321c8c4)
@@ -17,6 +17,10 @@ export declare class IoredisClient extends RedisClient {
17
17
  watch(args: string[], cb: ICallback<string>): void;
18
18
  unwatch(cb: ICallback<string>): void;
19
19
  sismember(key: string, member: string, cb: ICallback<number>): void;
20
+ sscan(key: string, options: {
21
+ MATCH?: string;
22
+ COUNT?: number;
23
+ }, cb: ICallback<string[]>): void;
20
24
  zcard(key: string, cb: ICallback<number>): void;
21
25
  zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
22
26
  psubscribe(pattern: string): void;
@@ -47,6 +47,28 @@ class IoredisClient extends redis_client_1.RedisClient {
47
47
  sismember(key, member, cb) {
48
48
  this.client.sismember(key, member, cb);
49
49
  }
50
+ sscan(key, options, cb) {
51
+ const result = new Set();
52
+ const iterate = (position) => {
53
+ const args = [key, position];
54
+ if (options.MATCH)
55
+ args.push('MATCH', options.MATCH);
56
+ if (options.COUNT)
57
+ args.push('COUNT', String(options.COUNT));
58
+ this.client.sscan(...args, (err, [cursor, items]) => {
59
+ if (err)
60
+ cb(err);
61
+ else {
62
+ items.forEach((i) => result.add(i));
63
+ if (cursor === '0')
64
+ cb(null, [...result]);
65
+ else
66
+ iterate(cursor);
67
+ }
68
+ });
69
+ };
70
+ iterate('0');
71
+ }
50
72
  zcard(key, cb) {
51
73
  this.client.zcard(key, cb);
52
74
  }
@@ -17,6 +17,10 @@ export declare class NodeRedisV3Client extends RedisClient {
17
17
  watch(args: string[], cb: ICallback<string>): void;
18
18
  unwatch(cb: ICallback<string>): void;
19
19
  sismember(key: string, member: string, cb: ICallback<number>): void;
20
+ sscan(key: string, options: {
21
+ MATCH?: string;
22
+ COUNT?: number;
23
+ }, cb: ICallback<string[]>): void;
20
24
  zcard(key: string, cb: ICallback<number>): void;
21
25
  zrange(key: string, min: number, max: number, cb: ICallback<string[]>): void;
22
26
  psubscribe(pattern: string): void;
@@ -74,6 +74,28 @@ class NodeRedisV3Client extends redis_client_1.RedisClient {
74
74
  sismember(key, member, cb) {
75
75
  this.client.sismember(key, member, cb);
76
76
  }
77
+ sscan(key, options, cb) {
78
+ const result = new Set();
79
+ const iterate = (position) => {
80
+ const args = [key, position];
81
+ if (options.MATCH)
82
+ args.push('MATCH', options.MATCH);
83
+ if (options.COUNT)
84
+ args.push('COUNT', String(options.COUNT));
85
+ this.client.sscan(...args, (err, [cursor, items]) => {
86
+ if (err)
87
+ cb(err);
88
+ else {
89
+ items.forEach((i) => result.add(i));
90
+ if (cursor === '0')
91
+ cb(null, [...result]);
92
+ else
93
+ iterate(cursor);
94
+ }
95
+ });
96
+ };
97
+ iterate('0');
98
+ }
77
99
  zcard(key, cb) {
78
100
  this.client.zcard(key, cb);
79
101
  }
@@ -25,6 +25,10 @@ export declare class NodeRedisV4Client extends RedisClient {
25
25
  unsubscribe(channel: string): void;
26
26
  zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
27
27
  smembers(key: string, cb: ICallback<string[]>): void;
28
+ sscan(key: string, options: {
29
+ MATCH?: string;
30
+ COUNT?: number;
31
+ }, cb: ICallback<string[]>): void;
28
32
  sadd(key: string, member: string, cb: ICallback<number>): void;
29
33
  hgetall(key: string, cb: ICallback<Record<string, string>>): void;
30
34
  hget(key: string, field: string, cb: ICallback<string | null>): void;
@@ -94,6 +94,27 @@ class NodeRedisV4Client extends redis_client_1.RedisClient {
94
94
  .then((reply) => cb(null, reply))
95
95
  .catch(cb);
96
96
  }
97
+ sscan(key, options, cb) {
98
+ const result = new Set();
99
+ const iterate = (position) => {
100
+ const args = [
101
+ key,
102
+ position,
103
+ options,
104
+ ];
105
+ this.client
106
+ .sScan(...args)
107
+ .then(({ cursor, members }) => {
108
+ members.forEach((i) => result.add(i));
109
+ if (cursor === 0)
110
+ cb(null, [...result]);
111
+ else
112
+ iterate(cursor);
113
+ })
114
+ .catch(cb);
115
+ };
116
+ iterate(0);
117
+ }
97
118
  sadd(key, member, cb) {
98
119
  this.client
99
120
  .sAdd(key, member)
@@ -12,7 +12,7 @@ export declare abstract class RedisClient extends EventEmitter {
12
12
  protected static scriptsLoaded: boolean;
13
13
  protected static luaScripts: LuaScripts;
14
14
  protected connectionClosed: boolean;
15
- protected validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
15
+ validateRedisVersion(major: number, feature?: number, minor?: number): boolean;
16
16
  abstract set(key: string, value: string, options: {
17
17
  expire?: {
18
18
  mode: 'EX' | 'PX';
@@ -33,6 +33,11 @@ export declare abstract class RedisClient extends EventEmitter {
33
33
  abstract unsubscribe(channel: string): void;
34
34
  abstract zrangebyscore(key: string, min: number | string, max: number | string, cb: ICallback<string[]>): void;
35
35
  abstract smembers(key: string, cb: ICallback<string[]>): void;
36
+ abstract sscan(key: string, options: {
37
+ MATCH?: string;
38
+ COUNT?: number;
39
+ }, cb: ICallback<string[]>): void;
40
+ sscanFallback(key: string, cb: ICallback<string[]>): void;
36
41
  abstract sadd(key: string, member: string, cb: ICallback<number>): void;
37
42
  abstract hgetall(key: string, cb: ICallback<Record<string, string>>): void;
38
43
  abstract hget(key: string, field: string, cb: ICallback<string | null>): void;
@@ -25,6 +25,12 @@ class RedisClient extends events_1.EventEmitter {
25
25
  RedisClient.redisServerVersion[1] >= feature &&
26
26
  RedisClient.redisServerVersion[2] >= minor));
27
27
  }
28
+ sscanFallback(key, cb) {
29
+ if (this.validateRedisVersion(2, 8))
30
+ this.sscan(key, {}, cb);
31
+ else
32
+ this.smembers(key, cb);
33
+ }
28
34
  zpophgetrpush(source, sourceHash, destination, cb) {
29
35
  this.runScript(ELuaScriptName.ZPOPHGETRPUSH, [source, sourceHash, destination], [], (err, res) => {
30
36
  if (err)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redis-smq-common",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",