Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: Implement move command #3369

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* Go: Add `FLUSHALL` ([#3117](https://github.com/valkey-io/valkey-glide/pull/3117))
* Go: Add `FLUSHDB` ([#3117](https://github.com/valkey-io/valkey-glide/pull/3117))
* Go: Add password update api ([#3346](https://github.com/valkey-io/valkey-glide/pull/3346))
* Go: Add `Move` ([#3369](https://github.com/valkey-io/valkey-glide/pull/3369))

#### Breaking Changes

Expand Down
2 changes: 2 additions & 0 deletions go/api/generic_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ package api
// [valkey.io]: https://valkey.io/commands/#generic
type GenericCommands interface {
CustomCommand(args []string) (interface{}, error)

Move(key string, dbIndex int64) (bool, error)
}
18 changes: 18 additions & 0 deletions go/api/generic_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package api

import (
"fmt"

"github.com/google/uuid"
)

func ExampleGlideClient_CustomCommand() {
Expand All @@ -16,3 +18,19 @@ func ExampleGlideClient_CustomCommand() {

// Output: PONG
}

func ExampleGlideClient_Move() {
var client *GlideClient = getExampleGlideClient() // example helper function
key := uuid.New().String()
_, err := client.Set(key, "hello")
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
result, err := client.Move(key, 2)
if err != nil {
fmt.Println("Glide example failed with an error: ", err)
}
fmt.Println(result)

// Output: true
}
21 changes: 21 additions & 0 deletions go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,24 @@ func (client *GlideClient) FlushDBWithOptions(mode options.FlushMode) (string, e
}
return handleStringResponse(result)
}

// Move key from the currently selected database to the database specified by dbIndex.
//
// Parameters:
//
// key - The key to move.
// dbIndex - The index of the database to move key to.
//
// Return value:
//
// Returns "OK".
//
// [valkey.io]: https://valkey.io/commands/move/
func (client *GlideClient) Move(key string, dbIndex int64) (bool, error) {
result, err := client.executeCommand(C.Move, []string{key, utils.IntToString(dbIndex)})
if err != nil {
return defaultBoolResponse, err
}

return handleBoolResponse(result)
}
10 changes: 10 additions & 0 deletions go/integTest/standalone_commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,3 +789,13 @@ func (suite *GlideTestSuite) TestUpdateConnectionPassword_ImmediateAuthWrongPass
_, err = adminClient.ConfigSet(map[string]string{"requirepass": ""})
assert.NoError(suite.T(), err)
}

func (suite *GlideTestSuite) TestMove() {
client := suite.defaultClient()
t := suite.T()
key := uuid.New().String()
suite.verifyOK(client.Set(key, "hello"))
result, err := client.Move(key, 2)
assert.Nil(t, err)
assert.True(suite.T(), result)
}
Loading