Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/bloom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@redis/bloom",
"version": "5.9.0-beta.0",
"version": "5.9.0-beta.1",
"license": "MIT",
"main": "./dist/lib/index.js",
"types": "./dist/lib/index.d.ts",
Expand All @@ -13,7 +13,7 @@
"release": "release-it"
},
"peerDependencies": {
"@redis/client": "^5.9.0-beta.0"
"@redis/client": "^5.9.0-beta.1"
},
"devDependencies": {
"@redis/test-utils": "*"
Expand Down
49 changes: 49 additions & 0 deletions packages/client/lib/client/enterprise-maintenance-manager.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import assert from "node:assert";
import { createClient } from "../../";

describe("EnterpriseMaintenanceManager does not prevent proper options parsing", () => {
it("should not throw when initializing without options", async () => {
const client = createClient();
assert.doesNotThrow(async () => {
//Expected to reject because there is no url or socket provided and there is no running server on localhost
await assert.rejects(client.connect);
});
});

it("should not throw when initializing without url/socket and with maint", async () => {
const client = createClient({
maintNotifications: "enabled",
RESP: 3,
});
assert.doesNotThrow(async () => {
//Expected to reject because there is no url or socket provided and there is no running server on localhost
await assert.rejects(client.connect);
});
});
it("should not throw when initializing with url and with maint", async () => {
const client = createClient({
maintNotifications: "enabled",
RESP: 3,
url: "redis://localhost:6379",
});
assert.doesNotThrow(async () => {
//Expected to reject because there is no url or socket provided and there is no running server on localhost
await assert.rejects(client.connect);
});
});

it("should not throw when initializing with socket and with maint", async () => {
const client = createClient({
maintNotifications: "enabled",
RESP: 3,
socket: {
host: "localhost",
port: 6379,
},
});
assert.doesNotThrow(async () => {
//Expected to reject because there is no url or socket provided and there is no running server on localhost
await assert.rejects(client.connect);
});
});
});
34 changes: 20 additions & 14 deletions packages/client/lib/client/enterprise-maintenance-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isIP } from "net";
import { lookup } from "dns/promises";
import assert from "node:assert";
import { setTimeout } from "node:timers/promises";
import RedisSocket from "./socket";
import RedisSocket, { RedisTcpSocketOptions } from "./socket";
import diagnostics_channel from "node:diagnostics_channel";

export const MAINTENANCE_EVENTS = {
Expand Down Expand Up @@ -64,12 +64,12 @@ export default class EnterpriseMaintenanceManager {
#client: Client;

static setupDefaultMaintOptions(options: RedisClientOptions) {
if (options.maintPushNotifications === undefined) {
options.maintPushNotifications =
if (options.maintNotifications === undefined) {
options.maintNotifications =
options?.RESP === 3 ? "auto" : "disabled";
}
if (options.maintMovingEndpointType === undefined) {
options.maintMovingEndpointType = "auto";
if (options.maintEndpointType === undefined) {
options.maintEndpointType = "auto";
}
if (options.maintRelaxedSocketTimeout === undefined) {
options.maintRelaxedSocketTimeout = 10000;
Expand All @@ -80,14 +80,20 @@ export default class EnterpriseMaintenanceManager {
}

static async getHandshakeCommand(
tls: boolean,
host: string,
options: RedisClientOptions,
): Promise<
| { cmd: Array<RedisArgument>; errorHandler: (error: Error) => void }
| undefined
> {
if (options.maintPushNotifications === "disabled") return;
if (options.maintNotifications === "disabled") return;

const host = options.url
? new URL(options.url).hostname
: (options.socket as RedisTcpSocketOptions | undefined)?.host;

if (!host) return;

const tls = options.socket?.tls ?? false

const movingEndpointType = await determineEndpoint(tls, host, options);
return {
Expand All @@ -100,7 +106,7 @@ export default class EnterpriseMaintenanceManager {
],
errorHandler: (error: Error) => {
dbgMaintenance("handshake failed:", error);
if (options.maintPushNotifications === "enabled") {
if (options.maintNotifications === "enabled") {
throw error;
}
},
Expand Down Expand Up @@ -189,7 +195,7 @@ export default class EnterpriseMaintenanceManager {
// reconnect to its currently configured endpoint after half of the grace
// period that was communicated by the server is over.
if (url === null) {
assert(this.#options.maintMovingEndpointType === "none");
assert(this.#options.maintEndpointType === "none");
assert(this.#options.socket !== undefined);
assert("host" in this.#options.socket);
assert(typeof this.#options.socket.host === "string");
Expand Down Expand Up @@ -329,12 +335,12 @@ async function determineEndpoint(
host: string,
options: RedisClientOptions,
): Promise<MovingEndpointType> {
assert(options.maintMovingEndpointType !== undefined);
if (options.maintMovingEndpointType !== "auto") {
assert(options.maintEndpointType !== undefined);
if (options.maintEndpointType !== "auto") {
dbgMaintenance(
`Determine endpoint type: ${options.maintMovingEndpointType}`,
`Determine endpoint type: ${options.maintEndpointType}`,
);
return options.maintMovingEndpointType;
return options.maintEndpointType;
}

const ip = isIP(host) ? host : (await lookup(host, { family: 0 })).address;
Expand Down
2 changes: 1 addition & 1 deletion packages/client/lib/client/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { strict as assert } from 'node:assert';
import testUtils, { GLOBAL, waitTillBeenCalled } from '../test-utils';
import RedisClient, { RedisClientOptions, RedisClientType } from '.';
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, ErrorReply, MultiErrorReply, SocketClosedUnexpectedlyError, TimeoutError, WatchError } from '../errors';
import { AbortError, ClientClosedError, ClientOfflineError, ConnectionTimeoutError, DisconnectsClientError, ErrorReply, MultiErrorReply, TimeoutError, WatchError } from '../errors';
import { defineScript } from '../lua-script';
import { spy, stub } from 'sinon';
import { once } from 'node:events';
Expand Down
Loading