@cap-js-community/event-queue 0.1.58 → 0.2.1

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.
@@ -29,9 +29,18 @@ const _createClientBase = () => {
29
29
  if (env.isOnCF) {
30
30
  try {
31
31
  const credentials = env.getRedisCredentialsFromEnv();
32
- // NOTE: settings the user explicitly to empty resolves auth problems, see
33
- // https://github.com/go-redis/redis/issues/1343
32
+ const redisIsCluster = credentials.cluster_mode;
34
33
  const url = credentials.uri.replace(/(?<=rediss:\/\/)[\w-]+?(?=:)/, "");
34
+ if (redisIsCluster) {
35
+ return redis.createCluster({
36
+ rootNodes: [{ url }],
37
+ // https://github.com/redis/node-redis/issues/1782
38
+ defaults: {
39
+ password: credentials.password,
40
+ socket: { tls: credentials.tls },
41
+ },
42
+ });
43
+ }
35
44
  return redis.createClient({ url });
36
45
  } catch (err) {
37
46
  throw EventQueueError.redisConnectionFailure(err);
@@ -87,9 +96,21 @@ const publishMessage = async (channel, message) => {
87
96
 
88
97
  const _localReconnectStrategy = () => EventQueueError.redisNoReconnect();
89
98
 
99
+ const closeMainClient = async () => {
100
+ try {
101
+ const client = await mainClientPromise;
102
+ if (client?.quit) {
103
+ await client.quit();
104
+ }
105
+ } catch (err) {
106
+ // ignore errors during shutdown
107
+ }
108
+ };
109
+
90
110
  module.exports = {
91
111
  createClientAndConnect,
92
112
  createMainClientAndConnect,
93
113
  subscribeRedisChannel,
94
114
  publishMessage,
115
+ closeMainClient,
95
116
  };