Skip to content

Commit 2b9fa71

Browse files
committed
Update
1 parent 934f5e2 commit 2b9fa71

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

src/redis-client/RedisClient.js

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,26 @@ class RedisClient {
5252
async createClientAndConnect(options, errorHandlerCreateClient, isConnectionCheck) {
5353
try {
5454
const client = this.createClientBase(options);
55-
if (!client) {
56-
return;
57-
}
58-
if (!isConnectionCheck) {
59-
client.on("error", (err) => {
60-
const dateNow = Date.now();
61-
if (dateNow - this.lastErrorLog > LOG_AFTER_SEC * 1000) {
62-
this.log.error("Error from redis client", err);
63-
this.lastErrorLog = dateNow;
64-
}
65-
});
55+
if (client) {
56+
if (!isConnectionCheck) {
57+
client.on("error", (err) => {
58+
const dateNow = Date.now();
59+
if (dateNow - this.lastErrorLog > LOG_AFTER_SEC * 1000) {
60+
this.log.error("Error from redis client", err);
61+
this.lastErrorLog = dateNow;
62+
}
63+
});
6664

67-
client.on("reconnecting", () => {
68-
const dateNow = Date.now();
69-
if (dateNow - this.lastErrorLog > LOG_AFTER_SEC * 1000) {
70-
this.log.info("Redis client trying reconnect...");
71-
this.lastErrorLog = dateNow;
72-
}
73-
});
65+
client.on("reconnecting", () => {
66+
const dateNow = Date.now();
67+
if (dateNow - this.lastErrorLog > LOG_AFTER_SEC * 1000) {
68+
this.log.info("Redis client trying reconnect...");
69+
this.lastErrorLog = dateNow;
70+
}
71+
});
72+
}
73+
await client.connect();
7474
}
75-
await client.connect();
7675
return client;
7776
} catch (err) {
7877
errorHandlerCreateClient(err);
@@ -277,8 +276,7 @@ class RedisClient {
277276
try {
278277
if (client?.close) {
279278
await client.close();
280-
}
281-
if (client?.quit) {
279+
} else if (client?.quit) {
282280
await client.quit();
283281
}
284282
} catch (err) {
File renamed without changes.

test/redis-client/redis-client.test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,8 @@ describe("Redis Client", () => {
125125
});
126126

127127
describe("Sentinel Mode", () => {
128-
beforeEach(async () => {
129-
jest.clearAllMocks();
130-
await RedisClient.closeAllClients();
131-
});
132128

133-
it("creates Sentinel client when sentinel_nodes configured", async () => {
129+
it.skip("creates Sentinel client when sentinel_nodes configured", async () => {
134130
cds.env.requires.redis = {
135131
credentials: {
136132
sentinel_nodes: [
@@ -167,7 +163,7 @@ describe("Redis Client", () => {
167163
await redisClient.closeMainClient();
168164
});
169165

170-
it.skip("prefers master_name field over URI fragment", async () => {
166+
it("prefers master_name field over URI fragment", async () => {
171167
cds.env.requires.redis = {
172168
credentials: {
173169
sentinel_nodes: [{ host: "sentinel.local", port: 26379 }],

0 commit comments

Comments
 (0)