diff --git a/go/api/base_client.go b/go/api/base_client.go index cdadc4cd14..7f73728656 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -3495,24 +3495,3 @@ func (client *baseClient) XClaimJustIdWithOptions( } return handleStringArrayResponse(result) } - -// Returns the server time. -// -// Return value: -// The current server time as a String array with two elements: -// A UNIX TIME and the amount of microseconds already elapsed in the current second. -// The returned array is in a [UNIX TIME, Microseconds already elapsed] format. -// -// For example: -// -// result, err := client.Time() -// result: [{1737051660} {994688}] -// -// [valkey.io]: https://valkey.io/commands/time/ -func (client *baseClient) Time() ([]string, error) { - result, err := client.executeCommand(C.Time, []string{}) - if err != nil { - return nil, err - } - return handleRawStringArrayResponse(result) -} diff --git a/go/api/glide_cluster_client.go b/go/api/glide_cluster_client.go index 3a7981b8ca..cc672a91b5 100644 --- a/go/api/glide_cluster_client.go +++ b/go/api/glide_cluster_client.go @@ -5,7 +5,6 @@ package api // #cgo LDFLAGS: -L../target/release -lglide_rs // #include "../lib.h" import "C" -import "github.com/valkey-io/valkey-glide/go/glide/api/options" // GlideClusterClient interface compliance check. var _ GlideClusterClient = (*glideClusterClient)(nil) @@ -14,7 +13,6 @@ var _ GlideClusterClient = (*glideClusterClient)(nil) type GlideClusterClient interface { BaseClient GenericClusterCommands - ServerManagementClusterCommands } // glideClusterClient implements cluster mode operations by extending baseClient functionality. @@ -43,33 +41,3 @@ func (client *glideClusterClient) CustomCommand(args []string) (ClusterValue[int } return CreateClusterValue(data), nil } - -// Returns the server time. -// -// See [valkey.io] for details. -// -// Parameters: -// -// options - The TimeOptions type. -// -// Return value: -// -// The current server time as a String array with two elements: A UNIX TIME and the amount -// of microseconds already elapsed in the current second. -// The returned array is in a [UNIX TIME, Microseconds already elapsed] format. -// -// Example: -// -// route := api.SimpleNodeRoute(api.RandomRoute) -// options := options.NewTimeOptionsBuilder().SetRoute(route) -// result, err := client.TimeWithOptions(route) -// fmt.Println(result.Value()) // Output: [1737285074 67888] -// -// [valkey.io]: https://valkey.io/commands/time/ -func (client *glideClusterClient) TimeWithOptions(opts *options.TimeOptions) (ClusterValue[[]string], error) { - result, err := client.executeCommandWithRoute(C.Time, []string{}, opts.Route) - if err != nil { - return CreateEmptyStringArrayClusterValue(), err - } - return handleTimeClusterResponse(result) -} diff --git a/go/api/options/time_options.go b/go/api/options/time_options.go deleted file mode 100644 index fdbd326ccb..0000000000 --- a/go/api/options/time_options.go +++ /dev/null @@ -1,16 +0,0 @@ -package options - -import "github.com/valkey-io/valkey-glide/go/glide/api/config" - -type TimeOptions struct { - Route config.Route -} - -func NewTimeOptionsBuilder() *TimeOptions { - return &TimeOptions{} -} - -func (timeOptions *TimeOptions) SetRoute(route config.Route) *TimeOptions { - timeOptions.Route = route - return timeOptions -} diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index 5f67147482..19116a6d2f 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -969,89 +969,3 @@ func handleXPendingDetailResponse(response *C.struct_CommandResponse) ([]XPendin return pendingDetails, nil } - -func handleRawStringArrayResponse(response *C.struct_CommandResponse) ([]string, error) { - defer C.free_command_response(response) - - typeErr := checkResponseType(response, C.Array, false) - if typeErr != nil { - return nil, typeErr - } - - slice := make([]string, 0, response.array_value_len) - for _, v := range unsafe.Slice(response.array_value, response.array_value_len) { - err := checkResponseType(&v, C.String, false) - if err != nil { - return nil, err - } - - if v.string_value == nil { - return nil, &errors.RequestError{Msg: "Unexpected nil string in array"} - } - - byteSlice := C.GoBytes(unsafe.Pointer(v.string_value), C.int(int64(v.string_value_len))) - slice = append(slice, string(byteSlice)) - } - - return slice, nil -} - -func handleRawStringArrayMapResponse(response *C.struct_CommandResponse) (map[string][]string, error) { - defer C.free_command_response(response) - typeErr := checkResponseType(response, C.Map, false) - if typeErr != nil { - return nil, typeErr - } - - result := make(map[string][]string) - for _, v := range unsafe.Slice(response.array_value, response.array_value_len) { - key, err := convertCharArrayToString(v.map_key, true) - if err != nil { - return nil, err - } - - err = checkResponseType(v.map_value, C.Array, false) - if err != nil { - return nil, err - } - - timeStrings := make([]string, 0, v.map_value.array_value_len) - for _, strVal := range unsafe.Slice(v.map_value.array_value, v.map_value.array_value_len) { - err := checkResponseType(&strVal, C.String, false) - if err != nil { - return nil, err - } - if strVal.string_value == nil { - return nil, &errors.RequestError{Msg: "Unexpected nil string in array"} - } - byteSlice := C.GoBytes(unsafe.Pointer(strVal.string_value), C.int(int64(strVal.string_value_len))) - timeStrings = append(timeStrings, string(byteSlice)) - } - - result[key.Value()] = timeStrings - } - - return result, nil -} - -func handleTimeClusterResponse(response *C.struct_CommandResponse) (ClusterValue[[]string], error) { - // Handle multi-node response - if err := checkResponseType(response, C.Map, true); err == nil { - mapData, err := handleRawStringArrayMapResponse(response) - if err != nil { - return CreateEmptyStringArrayClusterValue(), err - } - var times []string - for _, nodeTimes := range mapData { - times = append(times, nodeTimes...) - } - return CreateClusterMultiValue(times), nil - } - - // Handle single node response - data, err := handleRawStringArrayResponse(response) - if err != nil { - return CreateEmptyStringArrayClusterValue(), err - } - return CreateClusterSingleValue(data), nil -} diff --git a/go/api/response_types.go b/go/api/response_types.go index 7c47bad9fe..84de6aed7f 100644 --- a/go/api/response_types.go +++ b/go/api/response_types.go @@ -161,13 +161,6 @@ func CreateEmptyClusterValue() ClusterValue[interface{}] { } } -func CreateEmptyStringArrayClusterValue() ClusterValue[[]string] { - var empty []string - return ClusterValue[[]string]{ - value: Result[[]string]{val: empty, isNil: true}, - } -} - // XPendingSummary represents a summary of pending messages in a stream group. // It includes the total number of pending messages, the ID of the first and last pending messages, // and a list of consumer pending messages. diff --git a/go/api/server_management_cluster_commands.go b/go/api/server_management_cluster_commands.go deleted file mode 100644 index c4da3d09f4..0000000000 --- a/go/api/server_management_cluster_commands.go +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 - -package api - -import "github.com/valkey-io/valkey-glide/go/glide/api/options" - -// ServerManagementClusterCommands supports commands for the "Server Management Commands" group for cluster client. -// -// See [valkey.io] for details. -// -// [valkey.io]: https://valkey.io/commands/#server -type ServerManagementClusterCommands interface { - TimeWithOptions(timeOptions *options.TimeOptions) (ClusterValue[[]string], error) -} diff --git a/go/api/server_management_commands.go b/go/api/server_management_commands.go index b6e3b0ba8d..3653f17903 100644 --- a/go/api/server_management_commands.go +++ b/go/api/server_management_commands.go @@ -61,6 +61,4 @@ type ServerManagementCommands interface { // // [valkey.io]: https://valkey.io/commands/config-set/ ConfigSet(parameters map[string]string) (string, error) - - Time() ([]string, error) } diff --git a/go/integTest/cluster_commands_test.go b/go/integTest/cluster_commands_test.go index dd9548c0cc..142f0cf273 100644 --- a/go/integTest/cluster_commands_test.go +++ b/go/integTest/cluster_commands_test.go @@ -6,8 +6,6 @@ import ( "strings" "github.com/stretchr/testify/assert" - "github.com/valkey-io/valkey-glide/go/glide/api/config" - "github.com/valkey-io/valkey-glide/go/glide/api/options" ) func (suite *GlideTestSuite) TestClusterCustomCommandInfo() { @@ -29,43 +27,3 @@ func (suite *GlideTestSuite) TestClusterCustomCommandEcho() { // ECHO is routed to a single random node assert.Equal(suite.T(), "GO GLIDE GO", result.Value().(string)) } - -func (suite *GlideTestSuite) TestTime_RandomRoute() { - client := suite.defaultClusterClient() - route := config.SimpleNodeRoute(config.RandomRoute) - options := options.NewTimeOptionsBuilder().SetRoute(route) - result, err := client.TimeWithOptions(options) - - assert.NoError(suite.T(), err) - assert.NotNil(suite.T(), result) - assert.NotEmpty(suite.T(), result.Value()) - assert.IsType(suite.T(), "", result.Value()[0]) - assert.Equal(suite.T(), 2, len(result.Value())) -} - -func (suite *GlideTestSuite) TestTime_AllNodes_MultipleValues() { - client := suite.defaultClusterClient() - route := config.AllNodes - options := options.NewTimeOptionsBuilder().SetRoute(route) - result, err := client.TimeWithOptions(options) - assert.NoError(suite.T(), err) - assert.NotNil(suite.T(), result) - assert.NotEmpty(suite.T(), result.Value()) - - assert.Greater(suite.T(), len(result.Value()), 1) - - for _, timeStr := range result.Value() { - assert.IsType(suite.T(), "", timeStr) - } -} - -func (suite *GlideTestSuite) TestTime_ErrorHandling() { - client := suite.defaultClusterClient() - invalidRoute := config.NewByAddressRoute("invalidHost", 9999) - - options := options.NewTimeOptionsBuilder().SetRoute(invalidRoute) - result, err := client.TimeWithOptions(options) - - assert.NotNil(suite.T(), err) - assert.Empty(suite.T(), result.Value()) -} diff --git a/go/integTest/standalone_commands_test.go b/go/integTest/standalone_commands_test.go index 8d1b3a4528..ddb0631a94 100644 --- a/go/integTest/standalone_commands_test.go +++ b/go/integTest/standalone_commands_test.go @@ -4,9 +4,7 @@ package integTest import ( "fmt" - "strconv" "strings" - "time" "github.com/google/uuid" "github.com/valkey-io/valkey-glide/go/glide/api" @@ -387,34 +385,3 @@ func (suite *GlideTestSuite) TestSortReadOnlyWithOptions_SuccessfulSortByWeightA assert.Equal(suite.T(), "item1", sortResult[3].Value()) assert.Equal(suite.T(), "item3", sortResult[5].Value()) } - -func (suite *GlideTestSuite) TestTime_Success() { - client := suite.defaultClient() - results, err := client.Time() - - assert.Nil(suite.T(), err) - assert.Len(suite.T(), results, 2) - - now := time.Now().Unix() - 1 - - timestamp, err := strconv.ParseInt(results[0], 10, 64) - assert.Nil(suite.T(), err) - assert.Greater(suite.T(), timestamp, now) - - microseconds, err := strconv.ParseInt(results[1], 10, 64) - assert.Nil(suite.T(), err) - assert.Less(suite.T(), microseconds, int64(1000000)) -} - -func (suite *GlideTestSuite) TestTime_Error() { - client := suite.defaultClient() - - // Disconnect the client or simulate an error condition - client.Close() - - results, err := client.Time() - - assert.NotNil(suite.T(), err) - assert.Nil(suite.T(), results) - assert.IsType(suite.T(), &errors.ClosingError{}, err) -}