Skip to content

Commit ed83efd

Browse files
committed
node: Remove SELECT command support from cluster client
- Remove select() method from GlideClusterClient - Remove createSelect import from cluster client - Remove extensive test coverage for SELECT functionality - Remove database ID validation tests from client internals - Add minimal database ID test for cluster client configuration - Clean up ConfigurationError import that's no longer needed This change removes the SELECT command implementation that was added for Valkey 9.0+ cluster support, likely due to reliability concerns with database switching in cluster mode or to simplify the API. Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
1 parent 74ae712 commit ed83efd

File tree

4 files changed

+22
-776
lines changed

4 files changed

+22
-776
lines changed

node/src/GlideClusterClient.ts

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ import {
6060
createScriptExists,
6161
createScriptFlush,
6262
createScriptKill,
63-
createSelect,
6463
createTime,
6564
createUnWatch,
6665
} from ".";
@@ -1645,47 +1644,6 @@ export class GlideClusterClient extends BaseClient {
16451644
});
16461645
}
16471646

1648-
/**
1649-
* Changes the currently selected database on cluster nodes.
1650-
*
1651-
* This command routes to all nodes by default to maintain consistency across the cluster.
1652-
*
1653-
* **WARNING**: This command is NOT RECOMMENDED for production use.
1654-
* Upon reconnection, nodes will revert to the database_id specified
1655-
* in the client configuration (default: 0), NOT the database selected
1656-
* via this command.
1657-
*
1658-
* **RECOMMENDED APPROACH**: Use the `databaseId` parameter in client
1659-
* configuration instead:
1660-
*
1661-
* ```typescript
1662-
* const client = await GlideClusterClient.createClient({
1663-
* addresses: [{ host: "localhost", port: 6379 }],
1664-
* databaseId: 5 // Recommended: persists across reconnections
1665-
* });
1666-
* ```
1667-
*
1668-
*
1669-
* @see {@link https://valkey.io/commands/select/|valkey.io} for details.
1670-
*
1671-
* @param index - The index of the database to select.
1672-
* @returns A simple `"OK"` response.
1673-
*
1674-
* @example
1675-
* ```typescript
1676-
* // Example usage of select method (NOT RECOMMENDED)
1677-
* const result = await client.select(2);
1678-
* console.log(result); // Output: 'OK'
1679-
* // Note: Database selection will be lost on reconnection!
1680-
* ```
1681-
*
1682-
*/
1683-
public async select(index: number): Promise<"OK"> {
1684-
return this.createWritePromise(createSelect(index), {
1685-
decoder: Decoder.String,
1686-
});
1687-
}
1688-
16891647
/**
16901648
* Returns the number of keys in the database.
16911649
*

node/tests/GlideClientInternals.test.ts

Lines changed: 0 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
ClosingError,
1515
ClusterBatch,
1616
ClusterTransaction,
17-
ConfigurationError,
1817
convertGlideRecordToRecord,
1918
Decoder,
2019
GlideClient,
@@ -687,135 +686,6 @@ describe("SocketConnectionInternals", () => {
687686
closeTestResources(connection, server, socket);
688687
});
689688

690-
it("should pass database id with value 0", async () => {
691-
const { connection, server, socket } = await getConnectionAndSocket(
692-
(request: connection_request.ConnectionRequest) =>
693-
request.databaseId === 0,
694-
{
695-
addresses: [{ host: "foo" }],
696-
databaseId: 0,
697-
},
698-
);
699-
closeTestResources(connection, server, socket);
700-
});
701-
702-
it("should accept higher database id values in client-side validation", () => {
703-
// Test that client-side validation accepts higher database IDs (100)
704-
// Server-side validation will handle actual database limits during connection
705-
expect(() => {
706-
const config: BaseClientConfiguration = {
707-
addresses: [{ host: "foo" }],
708-
databaseId: 100,
709-
};
710-
// Configuration creation should not throw for high database IDs
711-
// Only negative or non-integer values should be rejected client-side
712-
expect(config.databaseId).toBe(100);
713-
}).not.toThrow();
714-
});
715-
716-
it("should accept very high database id values in client-side validation", () => {
717-
// Test that client-side validation accepts very high database IDs (999)
718-
// Server-side validation will handle actual database limits during connection
719-
expect(() => {
720-
const config: BaseClientConfiguration = {
721-
addresses: [{ host: "foo" }],
722-
databaseId: 999,
723-
};
724-
// Configuration creation should not throw for high database IDs
725-
// Only negative or non-integer values should be rejected client-side
726-
expect(config.databaseId).toBe(999);
727-
}).not.toThrow();
728-
});
729-
730-
it("should reject negative database id", async () => {
731-
await expect(async () => {
732-
const socket = new net.Socket();
733-
await GlideClient.__createClient(
734-
{
735-
addresses: [{ host: "foo" }],
736-
databaseId: -1,
737-
},
738-
socket,
739-
);
740-
}).rejects.toThrow(ConfigurationError);
741-
});
742-
743-
it("should reject non-integer database id", async () => {
744-
await expect(async () => {
745-
const socket = new net.Socket();
746-
await GlideClient.__createClient(
747-
{
748-
addresses: [{ host: "foo" }],
749-
databaseId: 1.5,
750-
},
751-
socket,
752-
);
753-
}).rejects.toThrow(ConfigurationError);
754-
});
755-
756-
it("should accept database id 0 explicitly", () => {
757-
expect(() => {
758-
const config: BaseClientConfiguration = {
759-
addresses: [{ host: "foo" }],
760-
databaseId: 0,
761-
};
762-
// Database ID 0 should be explicitly accepted
763-
expect(config.databaseId).toBe(0);
764-
}).not.toThrow();
765-
});
766-
767-
it("should accept various valid database id values", () => {
768-
const validDatabaseIds = [0, 1, 5, 15, 50, 100, 500, 999];
769-
770-
for (const databaseId of validDatabaseIds) {
771-
expect(() => {
772-
const config: BaseClientConfiguration = {
773-
addresses: [{ host: "foo" }],
774-
databaseId: databaseId,
775-
};
776-
// All non-negative integer database IDs should be accepted client-side
777-
// Server will validate the actual limits during connection
778-
expect(config.databaseId).toBe(databaseId);
779-
}).not.toThrow();
780-
}
781-
});
782-
783-
it("should handle undefined database id gracefully", () => {
784-
expect(() => {
785-
const config: BaseClientConfiguration = {
786-
addresses: [{ host: "foo" }],
787-
// databaseId not specified - should default to undefined
788-
};
789-
expect(config.databaseId).toBeUndefined();
790-
}).not.toThrow();
791-
});
792-
793-
it("should reject NaN database id", async () => {
794-
await expect(async () => {
795-
const socket = new net.Socket();
796-
await GlideClient.__createClient(
797-
{
798-
addresses: [{ host: "foo" }],
799-
databaseId: NaN,
800-
},
801-
socket,
802-
);
803-
}).rejects.toThrow(ConfigurationError);
804-
});
805-
806-
it("should reject Infinity database id", async () => {
807-
await expect(async () => {
808-
const socket = new net.Socket();
809-
await GlideClient.__createClient(
810-
{
811-
addresses: [{ host: "foo" }],
812-
databaseId: Infinity,
813-
},
814-
socket,
815-
);
816-
}).rejects.toThrow(ConfigurationError);
817-
});
818-
819689
it("should pass periodic checks disabled", async () => {
820690
const { connection, server, socket } = await getConnectionAndSocket(
821691
(request: connection_request.ConnectionRequest) =>

node/tests/GlideClusterClient.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2868,4 +2868,26 @@ describe("GlideClusterClient", () => {
28682868
},
28692869
TIMEOUT,
28702870
);
2871+
2872+
it.each([ProtocolVersion.RESP2, ProtocolVersion.RESP3])(
2873+
"should pass database id for cluster client_%p",
2874+
async (protocol) => {
2875+
// Skip test if version is below 9.0.0 (Valkey 9)
2876+
if (cluster.checkIfServerVersionLessThan("9.0.0")) return;
2877+
2878+
const client = await GlideClusterClient.createClient(
2879+
getClientConfigurationOption(cluster.getAddresses(), protocol, {
2880+
databaseId: 1,
2881+
}),
2882+
);
2883+
2884+
try {
2885+
// Simple test to verify the client works with the database ID
2886+
expect(await client.ping()).toEqual("PONG");
2887+
} finally {
2888+
client.close();
2889+
}
2890+
},
2891+
TIMEOUT,
2892+
);
28712893
});

0 commit comments

Comments
 (0)