Skip to content

Add Range and Limit support to ZSetOperations.rangeByScoreWithScores #3145

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

Conversation

kssumin
Copy link

@kssumin kssumin commented May 8, 2025

Overview

This PR adds support for the Range and Limit parameters to the rangeByScoreWithScores and reverseRangeByScoreWithScores methods in the ZSetOperations interface, enhancing flexibility and consistency with other methods in the API.

Description

The PR implements four new methods in the ZSetOperations interface:

  • rangeByScoreWithScores(K key, Range<Double> range)
  • rangeByScoreWithScores(K key, Range<Double> range, Limit limit)
  • reverseRangeByScoreWithScores(K key, Range<Double> range)
  • reverseRangeByScoreWithScores(K key, Range<Double> range, Limit limit)

This allows users to:

  • Use Range objects to define score boundaries with inclusion/exclusion control
  • Apply Limit to control result pagination
  • Create more expressive and flexible queries

Motivation

Currently, rangeByScoreWithScores methods only accept double parameters for min/max scores, which limits flexibility for boundary conditions and special values like infinity. Using Range and Limit objects provides a more powerful and consistent API.

This enhancement was requested in issue #3139 and relates to older issues #796 and #938, where @mp911de indicated these methods should be added.

Testing

Added both unit tests in DefaultZSetOperationsUnitTests and integration tests in DefaultZSetOperationsIntegrationTests to verify correct functionality.

The tests validate:

  • Range parameter handling with various boundary conditions

  • Limit parameter for pagination

  • Correct ordering of results for reverse operations

  • You have read the Spring Data contribution guidelines.

  • You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes.

  • You submit test cases (unit or integration tests) that back your changes.

  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

This commit adds support for the Range and Limit parameters to the
rangeByScoreWithScores and reverseRangeByScoreWithScores methods
in ZSetOperations interface.

The implementation follows the same pattern already used for other
methods like rangeByLex, providing a more flexible and consistent API
for working with Redis sorted sets.

New methods:
- rangeByScoreWithScores(K key, Range<Double> range)
- rangeByScoreWithScores(K key, Range<Double> range, Limit limit)
- reverseRangeByScoreWithScores(K key, Range<Double> range)
- reverseRangeByScoreWithScores(K key, Range<Double> range, Limit limit)

Unit and integration tests added to verify functionality.

Fixes spring-projects#3139
Related to spring-projects#796 and spring-projects#938

Signed-off-by: kssumin <[email protected]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 8, 2025
@kssumin kssumin closed this May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants