Skip to content

Commit 33339e3

Browse files
committed
new harmonized approach 3
1 parent 8533ab9 commit 33339e3

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/redis-adapter.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { CfEnv } = require("./shared/cf-env");
1212
const { Logger } = require("./shared/logger");
1313
const { HandlerCollection } = require("./shared/handler-collection");
1414
const { Semaphore } = require("./shared/semaphore");
15-
const { tryJsonParse, isObject } = require("./shared/static");
15+
const { tryJsonParse } = require("./shared/static");
1616

1717
const COMPONENT_NAME = "/RedisAdapter";
1818
const VERROR_CLUSTER_NAME = "RedisAdapterError";
@@ -98,8 +98,10 @@ const _getRedisOptionsTuple = () => {
9898
},
9999
};
100100

101-
const credentials = cfEnv.cfServiceCredentialsForLabel(CF_REDIS_SERVICE_LABEL);
101+
const credentials = __customCredentials || cfEnv.cfServiceCredentialsForLabel(CF_REDIS_SERVICE_LABEL);
102102
const hasCredentials = Object.keys(credentials).length > 0;
103+
104+
const isCluster = !!credentials.cluster_mode;
103105
const credentialClientOptions = hasCredentials
104106
? {
105107
password: credentials.password,
@@ -126,9 +128,6 @@ const _getRedisOptionsTuple = () => {
126128
},
127129
};
128130

129-
const isCluster = !!(__customClusterOptions ?? credentials.cluster_mode);
130-
const redisClusterOptions = isObject(__customClusterOptions) ? { ...__customClusterOptions } : undefined;
131-
132131
// NOTE: Azure and GCP have an object in their service binding credentials under tls, however it's filled
133132
// with nonsensical values like:
134133
// - "ca": "null", a literal string spelling null, or
@@ -146,7 +145,7 @@ const _getRedisOptionsTuple = () => {
146145
redisClientOptions.socket.reconnectStrategy = _localReconnectStrategy;
147146
}
148147

149-
__activeOptionsTuple = [isCluster, redisClientOptions, redisClusterOptions];
148+
__activeOptionsTuple = [isCluster, redisClientOptions];
150149
}
151150

152151
return __activeOptionsTuple;
@@ -161,10 +160,9 @@ const _getRedisOptionsTuple = () => {
161160
*/
162161
const _createClientBase = (clientName) => {
163162
try {
164-
const [isCluster, redisClientOptions, redisClusterOptions] = _getRedisOptionsTuple();
163+
const [isCluster, redisClientOptions] = _getRedisOptionsTuple();
165164
if (isCluster) {
166165
return redis.createCluster({
167-
...redisClusterOptions,
168166
rootNodes: [redisClientOptions], // NOTE: assume this ignores everything but socket/url
169167
// https://github.com/redis/node-redis/issues/1782
170168
defaults: redisClientOptions, // NOTE: assume this ignores socket/url

0 commit comments

Comments
 (0)