@hotmeshio/hotmesh 0.1.1 → 0.1.2

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -15,9 +15,9 @@ declare class IORedisStoreService extends StoreService<RedisClientType, RedisMul
15
15
  constructor(redisClient: RedisClientType);
16
16
  /**
17
17
  * When in cluster mode, the getMulti wrapper only
18
- * sends commands to the same node/shard.
19
- * All other commands are sent simultaneously
20
- * using Promise.all and are then collated
18
+ * sends commands to the same node/shard if they share a key.
19
+ * All other commands are sent simultaneouslyusing Promise.all
20
+ * and are then collated
21
21
  */
22
22
  getMulti(): RedisMultiType;
23
23
  exec(...args: any[]): Promise<string | string[] | string[][]>;
@@ -3,19 +3,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IORedisStoreService = void 0;
4
4
  const key_1 = require("../../../modules/key");
5
5
  const index_1 = require("../index");
6
+ const enums_1 = require("../../../modules/enums");
6
7
  class IORedisStoreService extends index_1.StoreService {
7
8
  constructor(redisClient) {
8
9
  super(redisClient);
9
10
  }
10
11
  /**
11
12
  * When in cluster mode, the getMulti wrapper only
12
- * sends commands to the same node/shard.
13
- * All other commands are sent simultaneously
14
- * using Promise.all and are then collated
13
+ * sends commands to the same node/shard if they share a key.
14
+ * All other commands are sent simultaneouslyusing Promise.all
15
+ * and are then collated
15
16
  */
16
17
  getMulti() {
17
18
  const my = this;
18
- if (process.env.HMSH_IS_CLUSTER === 'true') {
19
+ if (enums_1.HMSH_IS_CLUSTER) {
19
20
  const commands = [];
20
21
  const addCommand = (command, args) => {
21
22
  commands.push({ command, args });
@@ -28,12 +29,14 @@ class IORedisStoreService extends index_1.StoreService {
28
29
  async exec() {
29
30
  if (commands.length === 0)
30
31
  return [];
31
- const sameCommand = commands.every(cmd => cmd.command === commands[0].command);
32
- if (sameCommand) {
32
+ const sameKey = commands.every(cmd => {
33
+ return cmd.args[0] === commands[0].args[0];
34
+ });
35
+ if (sameKey) {
33
36
  const multi = my.redisClient.multi();
34
37
  commands.forEach(cmd => multi[cmd.command](...cmd.args));
35
38
  const results = await multi.exec();
36
- return results.map(item => item); // Extract the results from multi.exec response format
39
+ return results.map(item => item);
37
40
  }
38
41
  else {
39
42
  return Promise.all(commands.map(cmd => my.redisClient[cmd.command](...cmd.args)));
@@ -16,9 +16,9 @@ declare class RedisStoreService extends StoreService<RedisClientType, RedisMulti
16
16
  constructor(redisClient: RedisClientType);
17
17
  /**
18
18
  * When in cluster mode, the getMulti wrapper only
19
- * sends commands to the same node/shard.
20
- * All other commands are sent simultaneously
21
- * using Promise.all and are then collated
19
+ * sends commands to the same node/shard if they share a key.
20
+ * All other commands are sent simultaneouslyusing Promise.all
21
+ * and are then collated
22
22
  */
23
23
  getMulti(): RedisMultiType;
24
24
  exec(...args: any[]): Promise<string | string[] | string[][]>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RedisStoreService = void 0;
4
4
  const index_1 = require("../index");
5
+ const enums_1 = require("../../../modules/enums");
5
6
  class RedisStoreService extends index_1.StoreService {
6
7
  constructor(redisClient) {
7
8
  super(redisClient);
@@ -38,13 +39,13 @@ class RedisStoreService extends index_1.StoreService {
38
39
  }
39
40
  /**
40
41
  * When in cluster mode, the getMulti wrapper only
41
- * sends commands to the same node/shard.
42
- * All other commands are sent simultaneously
43
- * using Promise.all and are then collated
42
+ * sends commands to the same node/shard if they share a key.
43
+ * All other commands are sent simultaneouslyusing Promise.all
44
+ * and are then collated
44
45
  */
45
46
  getMulti() {
46
47
  const my = this;
47
- if (process.env.HMSH_IS_CLUSTER === 'true') {
48
+ if (enums_1.HMSH_IS_CLUSTER) {
48
49
  const commands = [];
49
50
  const addCommand = (command, args) => {
50
51
  commands.push({ command: command.toUpperCase(), args });
@@ -57,8 +58,10 @@ class RedisStoreService extends index_1.StoreService {
57
58
  async exec() {
58
59
  if (commands.length === 0)
59
60
  return [];
60
- const sameCommand = commands.every(cmd => cmd.command === commands[0].command);
61
- if (sameCommand) {
61
+ const sameKey = commands.every(cmd => {
62
+ return cmd.args[0] === commands[0].args[0];
63
+ });
64
+ if (sameKey) {
62
65
  const multi = my.redisClient.multi();
63
66
  commands.forEach(cmd => {
64
67
  if (cmd.command === 'ZADD') {
@@ -67,7 +70,7 @@ class RedisStoreService extends index_1.StoreService {
67
70
  return multi[cmd.command](...cmd.args);
68
71
  });
69
72
  const results = await multi.exec();
70
- return results.map(item => item); // Extract the results from multi.exec response format
73
+ return results.map(item => item);
71
74
  }
72
75
  else {
73
76
  return Promise.all(commands.map(cmd => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hotmeshio/hotmesh",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Unbreakable Workflows",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",