Skip to content

Commit f55433a

Browse files
committed
go: Remove Select command from cluster clients
- Remove Select method from ClusterClient and related interfaces - Delete comprehensive database_id integration tests - Remove Select command from batch operations - Remove Select examples and tests - Add example for cluster client with database_id configuration The Select command is being removed in favor of using the database_id configuration parameter, which provides persistent database selection across reconnections. Signed-off-by: affonsov <67347924+affonsov@users.noreply.github.com>
1 parent d884d51 commit f55433a

File tree

7 files changed

+24
-644
lines changed

7 files changed

+24
-644
lines changed

go/create_client_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,27 @@ func ExampleNewClusterClient() {
5454
// Output:
5555
// Client created and connected: *glide.ClusterClient
5656
}
57+
58+
func ExampleNewClusterClient_withDatabaseId() {
59+
// This WithDatabaseId for cluster requires Valkey 9.0+
60+
clientConf := config.NewClusterClientConfiguration().
61+
WithAddress(&getClusterAddresses()[0]).
62+
WithRequestTimeout(5 * time.Second).
63+
WithUseTLS(false).
64+
WithDatabaseId(1).
65+
WithSubscriptionConfig(
66+
config.NewClusterSubscriptionConfig().
67+
WithSubscription(config.PatternClusterChannelMode, "news.*").
68+
WithCallback(func(message *models.PubSubMessage, ctx any) {
69+
fmt.Printf("Received message on '%s': %s", message.Channel, message.Message)
70+
}, nil),
71+
)
72+
client, err := NewClusterClient(clientConf)
73+
if err != nil {
74+
fmt.Println("Failed to create a client and connect: ", err)
75+
}
76+
fmt.Printf("Client created and connected: %T", client)
77+
78+
// Output:
79+
// Client created and connected: *glide.ClusterClient
80+
}

go/glide_cluster_client.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -335,47 +335,6 @@ func (client *ClusterClient) CustomCommandWithRoute(ctx context.Context,
335335
return models.CreateClusterValue[any](data), nil
336336
}
337337

338-
// Select changes the currently selected database on cluster nodes.
339-
// The command will be routed to all primary nodes by default.
340-
//
341-
// WARNING: This command is NOT RECOMMENDED for production use.
342-
// Upon reconnection, nodes will revert to the database_id specified
343-
// in the client configuration (default: 0), NOT the database selected
344-
// via this command.
345-
//
346-
// RECOMMENDED APPROACH: Use the database_id parameter in client
347-
// configuration instead:
348-
//
349-
// config := &config.ClusterClientConfiguration{
350-
// Addresses: []config.NodeAddress{{Host: "localhost", Port: 6379}},
351-
// DatabaseId: &databaseId, // Recommended: persists across reconnections
352-
// }
353-
// client, err := NewClusterClient(config)
354-
//
355-
// CLUSTER BEHAVIOR: This command routes to all nodes by default
356-
// to maintain consistency across the cluster.
357-
//
358-
// See [valkey.io] for details.
359-
//
360-
// Parameters:
361-
//
362-
// ctx - The context for controlling the command execution.
363-
// index - The index of the database to select.
364-
//
365-
// Return value:
366-
//
367-
// A simple `"OK"` response.
368-
//
369-
// [valkey.io]: https://valkey.io/commands/select/
370-
func (client *ClusterClient) Select(ctx context.Context, index int64) (string, error) {
371-
result, err := client.executeCommand(ctx, C.Select, []string{utils.IntToString(index)})
372-
if err != nil {
373-
return models.DefaultStringResponse, err
374-
}
375-
376-
return handleOkResponse(result)
377-
}
378-
379338
// Pings the server.
380339
// The command will be routed to all primary nodes.
381340
//

go/integTest/cluster_commands_test.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,33 +2677,3 @@ func (suite *GlideTestSuite) TestBatchWithSingleNodeRoute() {
26772677
assert.Contains(suite.T(), res[0], "# Replication", "isAtomic = %v", isAtomic)
26782678
}
26792679
}
2680-
2681-
func (suite *GlideTestSuite) TestClusterSelect_WithValidIndex() {
2682-
suite.SkipIfServerVersionLowerThan("9.0.0", suite.T())
2683-
2684-
client := suite.defaultClusterClient()
2685-
index := int64(1)
2686-
suite.verifyOK(client.Select(context.Background(), index))
2687-
2688-
key := uuid.New().String()
2689-
value := uuid.New().String()
2690-
suite.verifyOK(client.Set(context.Background(), key, value))
2691-
2692-
res, err := client.Get(context.Background(), key)
2693-
suite.NoError(err)
2694-
assert.Equal(suite.T(), value, res.Value())
2695-
}
2696-
2697-
func (suite *GlideTestSuite) TestClusterSelect_InvalidIndex_OutOfBounds() {
2698-
suite.SkipIfServerVersionLowerThan("9.0.0", suite.T())
2699-
2700-
client := suite.defaultClusterClient()
2701-
2702-
result, err := client.Select(context.Background(), -1)
2703-
assert.NotNil(suite.T(), err)
2704-
assert.Equal(suite.T(), "", result)
2705-
2706-
result, err = client.Select(context.Background(), 1000)
2707-
assert.NotNil(suite.T(), err)
2708-
assert.Equal(suite.T(), "", result)
2709-
}

0 commit comments

Comments
 (0)