-
Notifications
You must be signed in to change notification settings - Fork 66
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: Add Zcount command #2930
Open
prateek-kumar-improving
wants to merge
15
commits into
main
Choose a base branch
from
go-zcount-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+212
−1
Open
Go: Add Zcount command #2930
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
197c965
Go: Zcount command
prateek-kumar-improving ab1f617
Go: Zcount remove options.go file
prateek-kumar-improving 4494208
Go: Added Range options
prateek-kumar-improving 01e3e67
Go: Update test cases
prateek-kumar-improving a15e8eb
Merge branch 'main' into go-zcount-command
prateek-kumar-improving f919b62
Go: ZCount: Add test and update documentation
prateek-kumar-improving 0f7df19
Go: changelog.md file updated
prateek-kumar-improving 6c66640
Go: Zcount documentation updated
prateek-kumar-improving acd4f7d
Go: Zcount fix formatting
prateek-kumar-improving cde0adb
Merge branch 'main' into go-zcount-command
prateek-kumar-improving e187bf7
Update ZCountRange builder
prateek-kumar-improving ee3ff0e
Go: Review comments fixed
prateek-kumar-improving dee5043
Go: Fix review comments
prateek-kumar-improving eb5bd11
Go: review comments fixed
prateek-kumar-improving 3f6ee4b
Merge branch 'main' into go-zcount-command
prateek-kumar-improving File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
package options | ||
|
||
import "github.com/valkey-io/valkey-glide/go/glide/utils" | ||
|
||
// The common interface for representing all the range type for Zcount command. | ||
type ScoreRange interface { | ||
ToArgs() ([]string, error) | ||
} | ||
|
||
type ( | ||
InfBoundary string | ||
) | ||
|
||
const ( | ||
// The highest bound in the sorted set | ||
PositiveInfinity InfBoundary = "+inf" | ||
// The lowest bound in the sorted set | ||
NegativeInfinity InfBoundary = "-inf" | ||
) | ||
|
||
// This struct represents the infinity boundary for a score range. | ||
type InfScoreBound struct { | ||
value InfBoundary | ||
} | ||
|
||
// Create a new infinite score boundary | ||
func NewInfScoreBoundBuilder() *InfScoreBound { | ||
return &InfScoreBound{} | ||
} | ||
|
||
// The value of the infinite score bound. | ||
func (infScoreBound *InfScoreBound) SetValue(value InfBoundary) *InfScoreBound { | ||
Yury-Fridlyand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
infScoreBound.value = value | ||
return infScoreBound | ||
} | ||
|
||
func (infScoreBound *InfScoreBound) ToArgs() ([]string, error) { | ||
args := []string{} | ||
args = append(args, string(infScoreBound.value)) | ||
return args, nil | ||
prateek-kumar-improving marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// This struct represents score boundary for a bound. | ||
type ScoreBoundary struct { | ||
bound float64 | ||
isInclusive bool | ||
} | ||
|
||
// Create a new score boundary. | ||
func NewScoreBoundaryBuilder() *ScoreBoundary { | ||
return &ScoreBoundary{isInclusive: true} | ||
} | ||
|
||
// Set the bound for a score boundary. | ||
func (scoreBoundary *ScoreBoundary) SetBound(bound float64) *ScoreBoundary { | ||
scoreBoundary.bound = bound | ||
return scoreBoundary | ||
} | ||
|
||
// Set if the bound for a score boundary is inclusive or not inclusive in the boundary. | ||
func (scoreBoundary *ScoreBoundary) SetIsInclusive(isInclusive bool) *ScoreBoundary { | ||
scoreBoundary.isInclusive = isInclusive | ||
return scoreBoundary | ||
} | ||
|
||
func (scoreBoundary *ScoreBoundary) ToArgs() ([]string, error) { | ||
args := []string{} | ||
if !scoreBoundary.isInclusive { | ||
args = append(args, "("+utils.FloatToString(scoreBoundary.bound)) | ||
} else { | ||
args = append(args, utils.FloatToString(scoreBoundary.bound)) | ||
} | ||
return args, nil | ||
} | ||
|
||
// This struct represents the min and max boundary for the Zcount command. | ||
type ZCountRange struct { | ||
min ScoreRange | ||
max ScoreRange | ||
} | ||
|
||
// Create a new Zcount range. | ||
func NewZCountRangeBuilder(min ScoreRange, max ScoreRange) *ZCountRange { | ||
zCountRange := &ZCountRange{} | ||
zCountRange.min = min | ||
zCountRange.max = max | ||
return zCountRange | ||
prateek-kumar-improving marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (zCountRange *ZCountRange) ToArgs() ([]string, error) { | ||
args := []string{} | ||
minArgs, err := zCountRange.min.ToArgs() | ||
if err != nil { | ||
return nil, err | ||
} | ||
args = append(args, minArgs...) | ||
maxArgs, err := zCountRange.max.ToArgs() | ||
if err != nil { | ||
return nil, err | ||
} | ||
args = append(args, maxArgs...) | ||
return args, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -262,4 +262,33 @@ type SortedSetCommands interface { | |||||
// [valkey.io]: https://valkey.io/commands/bzpopmin/ | ||||||
// [blocking commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands | ||||||
BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error) | ||||||
|
||||||
// Returns the number of members in the sorted set stored at `key` with scores between `min` and `max` score. | ||||||
// | ||||||
// See [valkey.io] for details. | ||||||
// | ||||||
// Parameters: | ||||||
// key - The key of the set. | ||||||
// rangeOptions - Contains `min` and `max` score. `min` contains the minimum score to count from. | ||||||
// `max` contains the maximum score to count up to. Can be positive/negative infinity, or | ||||||
// specific score and inclusivity. | ||||||
// | ||||||
// Return value: | ||||||
// Result[int64] - The number of members in the specified score range. | ||||||
prateek-kumar-improving marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// | ||||||
// Example: | ||||||
// key1 := uuid.NewString() | ||||||
// membersScores := map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0 } | ||||||
// zAddResult, err := client.ZAdd(key1, membersScores) | ||||||
// zCountRange := options.NewZCountRangeBuilder() | ||||||
// zCountRange.SetMin(options.NewInfScoreBoundBuilder().SetValue(options.NegativeInfinity)) | ||||||
// zCountRange.SetMax(options.NewInfScoreBoundBuilder().SetValue(options.PositiveInfinity)) | ||||||
prateek-kumar-improving marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// zCountResult, err := client.ZCount(key1, zCountRange) | ||||||
// if err!= nil { | ||||||
// // Print err | ||||||
// } | ||||||
// fmt.Println(zCountResult.Value()) // Output: 3 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// | ||||||
// [valkey.io]: https://valkey.io/commands/zcount/ | ||||||
ZCount(key string, rangeOptions *options.ZCountRange) (Result[int64], error) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
return value is not nullable
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.
Update tests accordingly