Using zset of redis for Atomic Addition and Statistics

  redis, springboot

Using zset of redis for Atomic Addition and Statistics

maven

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-redis</artifactId>
        </dependency>

incr

redisTemplate.boundZSetOps("myzset").incrementScore(key,1L);

sort

        int start = (page - 1) * PAGE_SIZE;
        int end = start + PAGE_SIZE - 1;
        Set<ZSetOperations.TypedTuple<String>> reportCodes = redisTemplate
                .boundZSetOps("myzset")
                .reverseRangeWithScores(start,end);

doc