Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

SpringBoot redis操作极慢

redis版本3.2(windows),SpringBoot版本2.3.1.RELEASE,就一个启动类:

@SpringBootApplication
public class DemoApplication implements CommandLineRunner {
    @Autowired
    private StringRedisTemplate redisTemplate;

    public static void main(String[] args) {
        new SpringApplicationBuilder(DemoApplication.class)
                .web(WebApplicationType.NONE)
                .run(args);
    }

    @Override
    public void run(String... args) {
        Instant start = Instant.now();

        for (int i = 0; i < 1; i++) {
            redisTemplate.opsForValue().set("test", String.valueOf(i), 1);
        }

        System.out.println(ChronoUnit.MILLIS.between(start, Instant.now()));
    }
}

redis配置文件:

spring:
  redis:
    host: localhost
    port: 6379

pom就1个依赖:

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

这个redis操作的耗时在1.5-1.7秒之间,但是在redis-cli里手动输命令就很快,这是什么问题啊?
而且最奇葩的是有一个旧项目没问题,但是新创建的项目全都有这个问题,有没有好心人帮帮忙,快绝望了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

不要相信第一次的执行时间,看之后的,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...