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 Sort, Sort ReadOnly and Sort Store commands #2888

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

niharikabhavaraju
Copy link
Contributor

Implementing the Sort, Sort ReadOnly and Sort Store commands in GO client.

Signed-off-by: Niharika Bhavaraju <[email protected]>
Signed-off-by: Niharika Bhavaraju <[email protected]>
@@ -279,6 +280,128 @@ func (listDirection ListDirection) toString() (string, error) {
}
}

const (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move these changes into a separate file under package options.

@@ -225,3 +225,254 @@ func (suite *GlideTestSuite) TestConfigSetAndGet_invalidArgs() {
assert.Equal(suite.T(), map[api.Result[string]]api.Result[string]{}, result2)
assert.Nil(suite.T(), err)
}

func (suite *GlideTestSuite) TestSortWithOptions_ExternalWeights() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this functionality specific to standalone or a particular version?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some SORT options (searching in multiple keys) available only in standalone mode.
It was planned to support this on server side in cluster mode with condition that all keys are mapped to the same slot. I don't know the status of this feature - could you check please?

@Yury-Fridlyand Yury-Fridlyand added the go golang wrapper label Jan 2, 2025
@@ -225,3 +225,254 @@ func (suite *GlideTestSuite) TestConfigSetAndGet_invalidArgs() {
assert.Equal(suite.T(), map[api.Result[string]]api.Result[string]{}, result2)
assert.Nil(suite.T(), err)
}

func (suite *GlideTestSuite) TestSortWithOptions_ExternalWeights() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some SORT options (searching in multiple keys) available only in standalone mode.
It was planned to support this on server side in cluster mode with condition that all keys are mapped to the same slot. I don't know the status of this feature - could you check please?

// Sorts the elements in the list, set, or sorted set at key and returns the result.
// The sort command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// To store the result into a new key, see {@link #sortStore(string, string)}.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix link formats (apply throughout)

go/api/generic_commands.go Show resolved Hide resolved
go/api/generic_commands.go Outdated Show resolved Hide resolved
go/api/generic_commands.go Outdated Show resolved Hide resolved
go/api/generic_commands.go Outdated Show resolved Hide resolved
go/api/command_options.go Outdated Show resolved Hide resolved
var args []string

if opts.Limit != nil {
args = append(args, LIMIT_COMMAND_STRING, fmt.Sprintf("%d", opts.Limit.Offset), fmt.Sprintf("%d", opts.Limit.Count))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not utils.IntToString() as it is done in other places?

@@ -11,7 +13,7 @@ type GenericBaseCommands interface {
// Del removes the specified keys from the database. A key is ignored if it does not exist.
//
// Note:
// In cluster mode, if keys in `keyValueMap` map to different hash slots, the command
// In cluster mode, if `key` and `destination` map to different hash slots, the command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In cluster mode, if `key` and `destination` map to different hash slots, the command
// In cluster mode, if `keys` map to different hash slots, the command

@@ -37,7 +39,7 @@ type GenericBaseCommands interface {
// Exists returns the number of keys that exist in the database
//
// Note:
// In cluster mode, if keys in `keyValueMap` map to different hash slots, the command
// In cluster mode, if `key` and `destination` map to different hash slots, the command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// In cluster mode, if `key` and `destination` map to different hash slots, the command
// In cluster mode, if `keys` map to different hash slots, the command

// This command is routed depending on the client's {@link ReadFrom} strategy.
//
// Note:
// In cluster mode, if `key` and `destination` map to different hash slots, the command
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no destination, but key names could be referenced in options

Comment on lines 41 to 70
// Limit Limits the range of elements
Limit *Limit

// OrderBy sets the order to sort by (ASC or DESC)
OrderBy OrderBy

// IsAlpha determines whether to sort lexicographically (true) or numerically (false)
IsAlpha bool

// ByPattern - a pattern to sort by external keys instead of by the elements stored at the key themselves. The
// pattern should contain an asterisk (*) as a placeholder for the element values, where the value
// from the key replaces the asterisk to create the key name. For example, if key
// contains IDs of objects, byPattern can be used to sort these IDs based on an
// attribute of the objects, like their weights or timestamps.
// Supported in cluster mode since Valkey version 8.0 and above.
ByPattern string

// A pattern used to retrieve external keys' values, instead of the elements at key.
// The pattern should contain an asterisk (*) as a placeholder for the element values, where the
// value from key replaces the asterisk to create the key name. This
// allows the sorted elements to be transformed based on the related keys values. For example, if
// key< contains IDs of users, getPatterns can be used to retrieve
// specific attributes of these users, such as their names or email addresses. E.g., if
// getPatterns is name_*, the command will return the values of the keys
// name_&lt;element&gt; for each sorted element. Multiple getPatterns
// arguments can be provided to retrieve multiple attributes. The special value # can
// be used to include the actual element from key being sorted. If not provided, only
// the sorted elements themselves are returned.
// Supported in cluster mode since Valkey version 8.0 and above.
GetPatterns []string // List of patterns to retrieve external keys' values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move all docs to the corresponding setters. I afraid doc of private fields won't be visible to a user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go golang wrapper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants