mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-27 01:30:51 +00:00
引入redisson
This commit is contained in:
parent
be7cbe2d6f
commit
16447c60ec
@ -55,6 +55,7 @@ novel-plus -- 父工程
|
||||
| Redis | 分布式缓存(缓存替换方案,默认关闭,一行配置开启)
|
||||
| ElasticSearch | 搜索引擎(搜索增强方案,默认关闭,一行配置开启)
|
||||
| RabbitMq | 消息队列(流量削峰,默认关闭,一行配置开启)
|
||||
| Redisson | 实现分布式锁
|
||||
| Lombok | 简化对象封装工具
|
||||
| Docker | 应用容器引擎
|
||||
| Mysql | 数据库服务
|
||||
|
@ -4,7 +4,7 @@ spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://127.0.0.1:3306/novel_plus?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
|
||||
username: root
|
||||
password: test123456
|
||||
password:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
#Redis服务器IP
|
||||
redis:
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user