@xrystal/core 3.55.11 → 3.55.12

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "Yusuf Yasir KAYGUSUZ",
3
3
  "name": "@xrystal/core",
4
- "version": "3.55.11",
4
+ "version": "3.55.12",
5
5
  "description": "Runtime framework and CLI for API services, frontends, and multi-repo workspaces",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -1,9 +1,20 @@
1
1
  export { resolveRedisSocketOptions } from './resolve-socket.js';
2
- import { createClient } from 'redis';
2
+ import { createClient, createSentinel } from 'redis';
3
3
  import { bindLoaderTmpSync } from '../../utils/helpers/tmp/loader-tmp-sync.js';
4
4
  import { readInfraLoaderEnabled } from '../../utils/helpers/loader-options/index.js';
5
5
  import { InfraLoaderEnum } from '../../utils/models/enums/index.js';
6
6
  import { resolveRedisSocketOptions } from './resolve-socket.js';
7
+ function parseSentinelRootNodes(csv) {
8
+ return csv
9
+ .split(',')
10
+ .map((part) => part.trim())
11
+ .filter(Boolean)
12
+ .map((part) => {
13
+ const [host, port] = part.split(':');
14
+ return { host: host.trim(), port: Number.parseInt(port || '26379', 10) };
15
+ })
16
+ .filter((n) => n.host.length > 0);
17
+ }
7
18
  export default class RedisForCore {
8
19
  #client = null;
9
20
  #system;
@@ -36,14 +47,36 @@ export default class RedisForCore {
36
47
  if (!uri) {
37
48
  return;
38
49
  }
39
- const client = createClient({
40
- url: uri,
41
- socket: resolveRedisSocketOptions(uri),
42
- });
50
+ const socketOpts = resolveRedisSocketOptions(uri);
51
+ const sentinelHosts = process.env.REDIS_SENTINEL_HOSTS?.trim();
52
+ const sentinelMaster = process.env.REDIS_SENTINEL_MASTER?.trim() || 'mymaster';
53
+ let client;
54
+ if (sentinelHosts) {
55
+ const rootNodes = parseSentinelRootNodes(sentinelHosts);
56
+ if (rootNodes.length === 0) {
57
+ throw new Error('REDIS_SENTINEL_HOSTS is set but empty after parse');
58
+ }
59
+ client = (await createSentinel({
60
+ name: sentinelMaster,
61
+ sentinelRootNodes: rootNodes,
62
+ nodeClientOptions: {
63
+ url: uri,
64
+ socket: socketOpts,
65
+ },
66
+ sentinelClientOptions: {
67
+ socket: socketOpts,
68
+ },
69
+ }).connect());
70
+ }
71
+ else {
72
+ client = (await createClient({
73
+ url: uri,
74
+ socket: socketOpts,
75
+ }).connect());
76
+ }
43
77
  client.on('error', (err) => {
44
78
  console.error(`Redis ${err}`);
45
79
  });
46
- await client.connect();
47
80
  this.#client = client;
48
81
  };
49
82
  teardown = async () => {