Databases 4 min read

Boost Spring Boot Redis Performance with Pipelining: 3× Faster Results

This article explains Redis' client‑server request model, introduces the pipeline technique, compares normal and pipelined requests, and provides Spring Boot code examples that demonstrate a three‑fold speed improvement when writing 100,000 keys.

Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Spring Full-Stack Practical Cases
Boost Spring Boot Redis Performance with Pipelining: 3× Faster Results

Redis Pipeline Technique

Redis is a TCP service based on a client‑server model and a request/response protocol. Typically a request follows two steps: the client sends a query and waits (often blocking) for a response, and the server processes the command and returns the result.

Comparison of Normal and Pipeline Request Models

RTT (Round‑Trip Time) is a key network performance metric representing the total delay from sending data to receiving the acknowledgment.

One‑way delay is generally considered as transmission delay t1 + propagation delay t2 + queuing delay t3.

Performance Comparison

Dependencies

<code>&lt;dependency&gt;
  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
  &lt;artifactId&gt;spring-boot-starter-data-redis&lt;/artifactId&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
  &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
  &lt;artifactId&gt;commons-pool2&lt;/artifactId&gt;
&lt;/dependency&gt;</code>

Configuration

<code>spring:
  redis:
    host: localhost
    port: 6379
    password: ******
    database: 4
    lettuce:
      pool:
        maxActive: 8
        maxIdle: 100
        minIdle: 10
        maxWait: -1</code>

Normal Method

<code>@Resource
private StringRedisTemplate stringRedisTemplate;

public void execNormal() {
    long start = System.currentTimeMillis();
    for (int i = 0; i < 100_000; i++) {
        stringRedisTemplate.opsForValue().set("k" + i, "v" + i);
    }
    System.out.println("耗时:" + (System.currentTimeMillis() - start) + " ms");
}</code>

Test result (normal method): total time about 47 seconds.

Pipeline Method

<code>public void execPipeline() {
    long start = System.currentTimeMillis();
    stringRedisTemplate.executePipelined(new RedisCallback<Object>() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            for (int i = 0; i < 100_000; i++) {
                connection.set(("pk" + i).getBytes(), ("pv" + i).getBytes());
            }
            return null;
        }
    });
    System.out.println("耗时:" + (System.currentTimeMillis() - start) + " ms");
}</code>

Test result (pipeline method): total time about 13 seconds, achieving more than three times speed improvement.

The demonstration confirms that using Redis pipelining in a Spring Boot application can dramatically reduce latency when executing massive write operations.

JavaPerformanceDatabaseRedisSpring BootPipelining
Spring Full-Stack Practical Cases
Written by

Spring Full-Stack Practical Cases

Full-stack Java development with Vue 2/3 front-end suite; hands-on examples and source code analysis for Spring, Spring Boot 2/3, and Spring Cloud.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.