-
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
base: main
Are you sure you want to change the base?
Go: Add Zcount command #2930
Conversation
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
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.
LGTM.
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: Prateek Kumar <[email protected]>
Signed-off-by: prateek-kumar-improving <[email protected]>
// specific score and inclusivity. | ||
// | ||
// Return value: | ||
// Result[int64] - The number of members in the specified score range. |
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.
// Result[int64] - The number of members in the specified score range. | |
// The number of members in the specified score range. |
// fmt.Println(zCountResult.Value()) // Output: 3 | ||
// | ||
// [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 comment
The reason will be displayed to describe this comment to others. Learn more.
ZCount(key string, rangeOptions *options.ZCountRange) (Result[int64], error) | |
ZCount(key string, rangeOptions *options.ZCountRange) (int64, error) |
// if err!= nil { | ||
// // Print err | ||
// } | ||
// fmt.Println(zCountResult.Value()) // Output: 3 |
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.
// fmt.Println(zCountResult.Value()) // Output: 3 | |
// fmt.Println(zCountResult) // Output: 3 |
@@ -376,4 +376,34 @@ type SortedSetCommands interface { | |||
// | |||
// [valkey.io]: https://valkey.io/commands/zrevrank/ | |||
ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error) | |||
|
|||
// Returns the number of members in the sorted set stored at `key` with scores between `min` and `max` score. |
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.
As discussed, move the entire doc to the implementation
return CreateNilInt64Result(), err | ||
} | ||
result, err := client.executeCommand(C.ZCount, append([]string{key}, zCountRangeArgs...)) | ||
} |
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.
you missed handleLongResponse
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.
might have deleted a line when resolving the merge conflict.
@@ -1579,6 +1579,14 @@ func (client *baseClient) Persist(key string) (Result[bool], error) { | |||
return handleBooleanResponse(result) | |||
} | |||
|
|||
func (client *baseClient) ZCount(key string, rangeOptions *options.ZCountRange) (Result[int64], error) { |
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.
func (client *baseClient) ZCount(key string, rangeOptions *options.ZCountRange) (Result[int64], error) { | |
func (client *baseClient) ZCount(key string, rangeOptions *options.ZCountRange) (int64, error) { |
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
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(value InfBoundary) *InfScoreBound { | ||
return &InfScoreBound{value: value} | ||
} | ||
|
||
func (infScoreBound *InfScoreBound) ToArgs() ([]string, error) { | ||
return []string{string(infScoreBound.value)}, nil | ||
} | ||
|
||
// 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 | ||
} |
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.
all this already implemented in another file
Issue link
This Pull Request is linked to issue (URL): #2833
Checklist
Before submitting the PR make sure the following are checked: