You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I encountered a problem at work. I want to calculate the difference from my previous or next score. I need to filter out the situations where I have the same score.
Since the rangeByScoreWithScores method in ZSetOperations currently doesn't have Range and Limit parameters, this is how I currently implement it.
public Double getDifferenceWithPreviousRank(String key, Long userId) {
Double score = redisTemplate.opsForZSet().score(key, userId.toString());
if (score == null) {
return 0D;
}
RedisConnection connection = redisTemplate.getRequiredConnectionFactory().getConnection();
byte[] serializeKey = redisTemplate.getStringSerializer().serialize(key);
Objects.requireNonNull(serializeKey);
Set<Tuple> resultSet = connection.zSetCommands()
.zRangeByScoreWithScores(serializeKey, Range.rightUnbounded(Range.Bound.exclusive(score)),
new Limit().offset(0).count(1));
Tuple result = CollectionUtil.getFirst(resultSet);
if (result == null || result.getScore() == null) {
return 0D;
}
return result.getScore() - score;
}
So I would like to ask if it is possible to add a Range and Limit parameter to rangeByScoreWithScores, after all, this is more convenient to use.
If possible, I would be happy to contribute a PR.
The text was updated successfully, but these errors were encountered:
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.
Fixesspring-projects#3139
Related to spring-projects#796 and spring-projects#938
Signed-off-by: [Your Full Name] <[email protected]>
Signed-off-by: kssumin <[email protected]>
Hi, I encountered a problem at work. I want to calculate the difference from my previous or next score. I need to filter out the situations where I have the same score.
Since the rangeByScoreWithScores method in ZSetOperations currently doesn't have Range and Limit parameters, this is how I currently implement it.
So I would like to ask if it is possible to add a Range and Limit parameter to rangeByScoreWithScores, after all, this is more convenient to use.
If possible, I would be happy to contribute a PR.
The text was updated successfully, but these errors were encountered: