eip-cloud-services 1.2.5 → 1.2.6

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/redis.js +25 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-cloud-services",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Houses a collection of helpers for connecting with Cloud services.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/redis.js CHANGED
@@ -53,6 +53,26 @@ const applyPrefix = (value) => {
53
53
  return value.startsWith(prefix) ? value : `${prefix}${value}`;
54
54
  };
55
55
 
56
+ const toPlainObject = ( value ) => {
57
+ if ( value && typeof value === 'object' && !Array.isArray ( value ) ) {
58
+ return value;
59
+ }
60
+ return {};
61
+ };
62
+
63
+ const getRedisOptionsForClient = ( clientId, { cluster = false } = {} ) => {
64
+ const baseOptions = toPlainObject ( config?.redis?.options );
65
+ const perClientOptions = toPlainObject ( config?.redis?.clientOptionsById?.[ clientId ] );
66
+ const mergedOptions = { ...baseOptions, ...perClientOptions };
67
+
68
+ // Preserve existing cluster behaviour (TLS by default) unless explicitly overridden.
69
+ if ( cluster && !Object.prototype.hasOwnProperty.call ( mergedOptions, 'tls' ) ) {
70
+ mergedOptions.tls = {};
71
+ }
72
+
73
+ return mergedOptions;
74
+ };
75
+
56
76
  /**
57
77
  * Creates or retrieves a Redis client instance based on a given client identifier.
58
78
  * If the client does not exist, it creates a new one, either connecting to a Redis Cluster
@@ -93,10 +113,11 @@ const getClient = async ( clientId = 'main' ) => {
93
113
  host: node.host,
94
114
  port: node.port
95
115
  } ) );
116
+ const redisOptions = getRedisOptionsForClient ( clientId, { cluster: true } );
96
117
 
97
118
  redisClient = new Redis.Cluster ( clusterNodes, {
98
119
  dnsLookup: (address, callback) => callback(null, address),
99
- redisOptions: config?.redis?.options || {tls: {} }
120
+ redisOptions
100
121
  } );
101
122
 
102
123
  // Await until the cluster is ready
@@ -113,9 +134,11 @@ const getClient = async ( clientId = 'main' ) => {
113
134
  throw new Error ( 'Redis Cluster is enabled but there were no cluster nodes defined in config.redis.cluster' );
114
135
  }
115
136
  else {
137
+ const redisOptions = getRedisOptionsForClient ( clientId );
116
138
  redisClient = new Redis ( {
117
139
  host: config?.redis?.host,
118
- port: config?.redis?.port
140
+ port: config?.redis?.port,
141
+ ...redisOptions
119
142
  } );
120
143
 
121
144
  redisClient.on ( 'error', error => {