Skip to content

Commit

Permalink
Added route,errors folders
Browse files Browse the repository at this point in the history
Signed-off-by: Niharika Bhavaraju <[email protected]>
  • Loading branch information
niharikabhavaraju committed Jan 23, 2025
1 parent bcc00a7 commit a04f0b3
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 253 deletions.
21 changes: 0 additions & 21 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
32 changes: 0 additions & 32 deletions go/api/glide_cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -14,7 +13,6 @@ var _ GlideClusterClient = (*glideClusterClient)(nil)
type GlideClusterClient interface {
BaseClient
GenericClusterCommands
ServerManagementClusterCommands
}

// glideClusterClient implements cluster mode operations by extending baseClient functionality.
Expand Down Expand Up @@ -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)
}
16 changes: 0 additions & 16 deletions go/api/options/time_options.go

This file was deleted.

86 changes: 0 additions & 86 deletions go/api/response_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
7 changes: 0 additions & 7 deletions go/api/response_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 0 additions & 14 deletions go/api/server_management_cluster_commands.go

This file was deleted.

2 changes: 0 additions & 2 deletions go/api/server_management_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
42 changes: 0 additions & 42 deletions go/integTest/cluster_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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())
}
33 changes: 0 additions & 33 deletions go/integTest/standalone_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ package integTest

import (
"fmt"
"strconv"
"strings"
"time"

"github.com/google/uuid"
"github.com/valkey-io/valkey-glide/go/glide/api"
Expand Down Expand Up @@ -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)
}

0 comments on commit a04f0b3

Please sign in to comment.