Add incrementScore to RedisZSet
Opened this issue · 2 comments
vinsguru commented
RedisZSet provides a convenient collection-like abstraction around Redis sorted sets (ZSET).
However, it currently lacks a method for the most common operation on sorted sets like incrementing a member’s score (ZINCRBY).
Developers have to use ZSetOperations manually:
redisTemplate.opsForZSet().incrementScore(key, member, delta);
This defeats the purpose of using RedisZSet, which is intended to offer a unified, object-oriented API over ZSET operations.
Proposed Solution
Add a new default method to RedisZSet:
default Double incrementScore(V value, double delta) {
return getOperations().opsForZSet().incrementScore(getKey(), value, delta);
}
This aligns with the existing ZSetOperations.incrementScore() method and allows idiomatic usage:
var leaderboard = RedisZSet.create("leaderboard", ops, 0.0);
leaderboard.incrementScore("player:7", 5.0);
mp911de commented
Thanks for your suggestion. Such an extension makes sense. Do you would like to submit a pull request?