-
Notifications
You must be signed in to change notification settings - Fork 65
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
base: main
Are you sure you want to change the base?
Go: Implement Sort, Sort ReadOnly and Sort Store commands #2888
Conversation
10c81db
to
072f75b
Compare
Signed-off-by: Niharika Bhavaraju <[email protected]>
Signed-off-by: Niharika Bhavaraju <[email protected]>
072f75b
to
ca3c534
Compare
go/api/command_options.go
Outdated
@@ -279,6 +280,128 @@ func (listDirection ListDirection) toString() (string, error) { | |||
} | |||
} | |||
|
|||
const ( |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
@@ -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() { |
There was a problem hiding this comment.
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?
go/api/generic_commands.go
Outdated
// 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)}. |
There was a problem hiding this comment.
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/command_options.go
Outdated
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)) |
There was a problem hiding this comment.
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?
Signed-off-by: Niharika Bhavaraju <[email protected]>
go/api/generic_commands.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
go/api/generic_commands.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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 |
go/api/generic_commands.go
Outdated
// 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 |
There was a problem hiding this comment.
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
go/api/options/sort_options.go
Outdated
// 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_<element> 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 |
There was a problem hiding this comment.
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.
Signed-off-by: Niharika Bhavaraju <[email protected]>
…ey-glide into niharika-sortcmds
Implementing the Sort, Sort ReadOnly and Sort Store commands in GO client.