spring-data-redis icon indicating copy to clipboard operation
spring-data-redis copied to clipboard

Add incrementScore to RedisZSet

Open vinsguru opened this issue 1 month ago • 2 comments

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);

vinsguru avatar Nov 04 '25 11:11 vinsguru