mirror of
https://github.com/201206030/novel-plus.git
synced 2025-06-24 04:46:37 +00:00
引入redisson
This commit is contained in:
@ -45,6 +45,14 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<!--引入redisson分布式锁-->
|
||||
<!-- <dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson-spring-boot-starter</artifactId>
|
||||
<version>${redisson.version}</version>
|
||||
</dependency>-->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-sdk-java</artifactId>
|
||||
|
@ -37,6 +37,8 @@ public class BookVisitAddListener {
|
||||
|
||||
private final SearchService searchService;
|
||||
|
||||
// private final RedissonClient redissonClient;
|
||||
|
||||
|
||||
|
||||
|
||||
@ -51,11 +53,19 @@ public class BookVisitAddListener {
|
||||
log.debug("收到更新数据库消息:" + bookId);
|
||||
Thread.sleep(1000 * 2);
|
||||
//TODO 操作共享资源visitCount,集群环境下有线程安全问题,引入Redisson框架实现分布式锁
|
||||
//RLock lock = redissonClient.getLock("visitCount");
|
||||
//lock.lock();
|
||||
|
||||
|
||||
//目前visitCount不重要,数据可丢失,暂不实现分布式锁
|
||||
Integer visitCount = (Integer) cacheService.getObject(CacheKey.BOOK_ADD_VISIT_COUNT+bookId);
|
||||
if(visitCount == null){
|
||||
visitCount = 0 ;
|
||||
}
|
||||
|
||||
//TODO 操作共享资源visitCount,集群环境下有线程安全问题,引入Redisson框架实现分布式锁
|
||||
//lock.unlock();
|
||||
|
||||
cacheService.setObject(CacheKey.BOOK_ADD_VISIT_COUNT+bookId,++visitCount);
|
||||
if(cacheService.get(CacheKey.ES_IS_UPDATE_VISIT + bookId) == null) {
|
||||
bookService.addVisitCount(bookId);
|
||||
|
@ -25,7 +25,9 @@ spring:
|
||||
jest:
|
||||
uris: http://127.0.0.1:9200
|
||||
|
||||
|
||||
redisson:
|
||||
singleServerConfig:
|
||||
address: 127.0.0.1:6379
|
||||
|
||||
jwt:
|
||||
secret: novel!#20191230
|
||||
|
Reference in New Issue
Block a user