2019年3月15日 | Leave a comment 解决: @Bean public CommandLineRunner r(StringRedisTemplate redis) { return (argv) -> { final var key = "tfh_l1"; for (int i = 0; i < 60; i++) { final var op = redis.opsForList(); op.rightPush(key, "i:" + i); redis.expire(key, 2, TimeUnit.MINUTES); Thread.sleep(1000); } }; } 123456789101112 @Bean public CommandLineRunner r(StringRedisTemplate redis) { return (argv) -> { final var key = "tfh_l1"; for (int i = 0; i < 60; i++) { final var op = redis.opsForList(); op.rightPush(key, "i:" + i); redis.expire(key, 2, TimeUnit.MINUTES); Thread.sleep(1000); } }; } application.yaml spring: redis: # host: 127.0.0.1 # password: "123456" host: 172.16.16.21 port: 6379 123456 spring: redis:# host: 127.0.0.1# password: "123456" host: 172.16.16.21 port: 6379 参考: