Redis教程

io.lettuce.core.RedisCommandTimeoutException: Command timed out 的Redis操作问题

本文主要是介绍io.lettuce.core.RedisCommandTimeoutException: Command timed out 的Redis操作问题,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.依赖的问题,升级到spring 2.x

   <!-- Redis 依赖 -->
   	<dependency>
   		<groupId>org.springframework.boot</groupId>
   		<artifactId>spring-boot-starter-data-redis</artifactId>
   		<version>2.1.6.RELEASE</version>
   	</dependency>
   	<!-- spring2.X集成redis所需common-pool2-->
   	<dependency>
   		<groupId>org.apache.commons</groupId>
   		<artifactId>commons-pool2</artifactId>
   		<version>2.6.2</version>
   	</dependency>

2.配置

spring:
  redis:
    database: 1
    host: 101.34.177.108
    port: 6379
    password: lPhx@FQvbRoQGCke
    timeout: 60000
    lettuce:
      pool:
        max-active: 50
        max-wait: -1
        max-idle: 50
        min-idle: 0

我是多线程操作

@Slf4j
@Component
public class ReplaceLazadaAttrTask {
	@Autowired
	private LazadaApiClient lazadaApiClient;

	@Qualifier("threadPoolTaskExecutor")
	@Autowired
	private ThreadPoolTaskExecutor poolTaskExecutor;
	//@Scheduled(cron = "0 8 4 * * THU" )
	@Scheduled(cron = "0 15 11 * * FRI")
	public void toUpdateLazadaAttr() {
		log.info("定时更新lazada属性任务开始,开始执行时间:{}", LocalDateTime.now().toString());
		List<String> siteList = new ArrayList<>();
		siteList.add("SG");
		siteList.add("MY");
		siteList.add("VN");
		siteList.add("TH");
		siteList.add("PH");
		siteList.add("ID");
		siteList.forEach(s -> CompletableFuture.runAsync(() -> lazadaApiClient.toUpdateLazadaAttr(s),poolTaskExecutor));
		log.info("定时更新lazada属性任务结束,结束执行时间:{}", LocalDateTime.now().toString());
	}
}

这篇关于io.lettuce.core.RedisCommandTimeoutException: Command timed out 的Redis操作问题的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!