You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node: Add Multi-Database Support for Cluster Mode (Valkey 9.0) (#4657)
* - Implement database selection for cluster clients when database_id != 0
- Send SELECT command to all cluster nodes using MultiNode routing
- Add comprehensive error handling with clear error messages
- Include test for database selection error handling in cluster mode
- Support backward compatibility with servers that don't support multi-db cluster mode
- Enable cluster-databases=16 for Valkey 9.0+ in cluster manager
This enables cluster clients to work with non-default databases on Valkey 9.0+
servers configured with cluster-databases support, while gracefully handling
older servers that don't support this feature.
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* update valkey9 multi db tests
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* fix lint
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* fixing valkey 9 cluster tests
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* add to route to all nodes in the core
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* rust lint fix
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* implement database selection in cluster mode via connection parameters
- Add database_id field to ClusterParams and BuilderParams structs
- Add database() method to ClusterClientBuilder for setting database ID
- Pass database_id through connection info instead of post-connection SELECT
- Remove SELECT command from cluster routing
- Remove post-connection SELECT command logic from create_cluster_client
- Add comprehensive tests for database isolation and reconnection behavior
- Verify database ID persistence across node reconnections
- Test multi-database cluster support with proper isolation verification
This change moves database selection from a post-connection SELECT command
to a connection parameter, which is more reliable for cluster mode and
handles reconnections automatically. The approach works with servers that
support multi-database cluster configurations (like Valkey 9.0+).
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* add valkey9 constraint in the core tests
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* fix core test not skipping test when version was lower than valkey 9
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* Fix version check
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* refactored test test_set_database_id_after_reconnection to be similar from standalone
removed is_valkey_9_or_higher
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* removed tests and cleanup
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* renamed builder.database to builder.database_id
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* node changes
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* move tests to sharedtests.ts
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* reafactoring to select to all nodes being in the core
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* 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>
* added changelog
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* fix test, and removed comment
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
---------
Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
* - **Reconnection**: Database selection persists across reconnections.
673
+
* - **Default**: If not specified, defaults to database 0.
674
+
* - **Range**: Must be non-negative. The server will validate the upper limit based on its configuration.
675
+
* - **Server Validation**: The server determines the maximum database ID based on its `databases` configuration (standalone) or `cluster-databases` configuration (cluster mode).
676
+
*
677
+
* @example
678
+
* ```typescript
679
+
* // Connect to database 5
680
+
* const config: BaseClientConfiguration = {
681
+
* addresses: [{ host: 'localhost', port: 6379 }],
682
+
* databaseId: 5
683
+
* };
684
+
*
685
+
* // Connect to a higher database ID (server will validate the limit)
686
+
* const configHighDb: BaseClientConfiguration = {
687
+
* addresses: [{ host: 'localhost', port: 6379 }],
688
+
* databaseId: 100
689
+
* };
690
+
* ```
691
+
*/
692
+
databaseId?: number;
658
693
/**
659
694
* True if communication with the cluster should use Transport Level Security.
660
695
* Should match the TLS configuration of the server/cluster,
@@ -1164,15 +1199,13 @@ export class BaseClient {
1164
1199
}
1165
1200
}
1166
1201
1167
-
/**
1168
-
* @internal
1169
-
*/
1170
1202
protectedconstructor(
1171
1203
socket: net.Socket,
1172
1204
options?: BaseClientConfiguration,
1173
1205
){
1174
1206
// if logger has been initialized by the external-user on info level this log will be shown
* databaseId: 5, // Connect to database 5 (requires Valkey 9.0+ with multi-database cluster mode)
169
174
* periodicChecks: {
170
175
* duration_in_sec: 30, // Perform periodic checks every 30 seconds
171
176
* },
@@ -544,12 +549,12 @@ export class GlideClusterClient extends BaseClient {
544
549
/**
545
550
* Creates a new `GlideClusterClient` instance and establishes connections to a Valkey Cluster.
546
551
*
547
-
* @param options - The configuration options for the client, including cluster addresses, authentication credentials, TLS settings, periodic checks, and Pub/Sub subscriptions.
552
+
* @param options - The configuration options for the client, including cluster addresses, database selection, authentication credentials, TLS settings, periodic checks, and Pub/Sub subscriptions.
548
553
* @returns A promise that resolves to a connected `GlideClusterClient` instance.
549
554
*
550
555
* @remarks
551
556
* Use this static method to create and connect a `GlideClusterClient` to a Valkey Cluster.
552
-
* The client will automatically handle connection establishment, including cluster topology discovery and handling of authentication and TLS configurations.
557
+
* The client will automatically handle connection establishment, including cluster topology discovery, database selection, and handling of authentication and TLS configurations.
553
558
*
554
559
* @example
555
560
* ```typescript
@@ -561,6 +566,7 @@ export class GlideClusterClient extends BaseClient {
@@ -589,6 +595,7 @@ export class GlideClusterClient extends BaseClient {
589
595
*
590
596
* @remarks
591
597
* - **Cluster Topology Discovery**: The client will automatically discover the cluster topology based on the seed addresses provided.
598
+
* - **Database Selection**: Use `databaseId` to specify which logical database to connect to. Requires Valkey 9.0+ with multi-database cluster mode enabled.
592
599
* - **Authentication**: If `credentials` are provided, the client will attempt to authenticate using the specified username and password.
593
600
* - **TLS**: If `useTLS` is set to `true`, the client will establish secure connections using TLS.
594
601
* Should match the TLS configuration of the server/cluster, otherwise the connection attempt will fail.
0 commit comments