diff --git a/src/medicine/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_yaml_2_15_2.xml b/src/medicine/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_yaml_2_15_2.xml
new file mode 100644
index 00000000..05deea40
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_fasterxml_jackson_dataformat_jackson_dataformat_yaml_2_15_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml b/src/medicine/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml
new file mode 100644
index 00000000..810eb863
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_google_code_findbugs_jsr305_3_0_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_3_4.xml b/src/medicine/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_3_4.xml
new file mode 100644
index 00000000..fdcc3a4e
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_google_errorprone_error_prone_annotations_2_3_4.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml b/src/medicine/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml
new file mode 100644
index 00000000..e462b823
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_google_guava_failureaccess_1_0_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__com_google_guava_guava_29_0_jre.xml b/src/medicine/.idea/libraries/Maven__com_google_guava_guava_29_0_jre.xml
new file mode 100644
index 00000000..413df057
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_google_guava_guava_29_0_jre.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml b/src/medicine/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml
new file mode 100644
index 00000000..1bc1dd5e
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml b/src/medicine/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml
new file mode 100644
index 00000000..b46e2f91
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__com_google_j2objc_j2objc_annotations_1_3.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__io_netty_netty_codec_dns_4_1_94_Final.xml b/src/medicine/.idea/libraries/Maven__io_netty_netty_codec_dns_4_1_94_Final.xml
new file mode 100644
index 00000000..f030f38e
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__io_netty_netty_codec_dns_4_1_94_Final.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__io_netty_netty_resolver_dns_4_1_94_Final.xml b/src/medicine/.idea/libraries/Maven__io_netty_netty_resolver_dns_4_1_94_Final.xml
new file mode 100644
index 00000000..fb3b9df2
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__io_netty_netty_resolver_dns_4_1_94_Final.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__io_reactivex_rxjava3_rxjava_3_1_6.xml b/src/medicine/.idea/libraries/Maven__io_reactivex_rxjava3_rxjava_3_1_6.xml
new file mode 100644
index 00000000..cf2e3307
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__io_reactivex_rxjava3_rxjava_3_1_6.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__javax_cache_cache_api_1_1_1.xml b/src/medicine/.idea/libraries/Maven__javax_cache_cache_api_1_1_1.xml
new file mode 100644
index 00000000..0dcbbc78
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__javax_cache_cache_api_1_1_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__org_checkerframework_checker_qual_2_11_1.xml b/src/medicine/.idea/libraries/Maven__org_checkerframework_checker_qual_2_11_1.xml
new file mode 100644
index 00000000..1a9d90c9
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__org_checkerframework_checker_qual_2_11_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__org_jboss_marshalling_jboss_marshalling_2_0_10_Final.xml b/src/medicine/.idea/libraries/Maven__org_jboss_marshalling_jboss_marshalling_2_0_10_Final.xml
new file mode 100644
index 00000000..6308bf9c
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__org_jboss_marshalling_jboss_marshalling_2_0_10_Final.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__org_jboss_marshalling_jboss_marshalling_river_2_0_10_Final.xml b/src/medicine/.idea/libraries/Maven__org_jboss_marshalling_jboss_marshalling_river_2_0_10_Final.xml
new file mode 100644
index 00000000..2c782f26
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__org_jboss_marshalling_jboss_marshalling_river_2_0_10_Final.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__org_jodd_jodd_bean_5_1_6.xml b/src/medicine/.idea/libraries/Maven__org_jodd_jodd_bean_5_1_6.xml
new file mode 100644
index 00000000..50332125
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__org_jodd_jodd_bean_5_1_6.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__org_jodd_jodd_core_5_1_6.xml b/src/medicine/.idea/libraries/Maven__org_jodd_jodd_core_5_1_6.xml
new file mode 100644
index 00000000..da853ad1
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__org_jodd_jodd_core_5_1_6.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/libraries/Maven__org_redisson_redisson_3_14_1.xml b/src/medicine/.idea/libraries/Maven__org_redisson_redisson_3_14_1.xml
new file mode 100644
index 00000000..38bbc428
--- /dev/null
+++ b/src/medicine/.idea/libraries/Maven__org_redisson_redisson_3_14_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/medicine/.idea/sonarlint/issuestore/0/b/0bf6f777ae20a7657065bc4a2b2a9f1f3b4876b1 b/src/medicine/.idea/sonarlint/issuestore/0/b/0bf6f777ae20a7657065bc4a2b2a9f1f3b4876b1
new file mode 100644
index 00000000..607c6d7f
--- /dev/null
+++ b/src/medicine/.idea/sonarlint/issuestore/0/b/0bf6f777ae20a7657065bc4a2b2a9f1f3b4876b1
@@ -0,0 +1,5 @@
+
+t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(
+F
+java:S1128
+"+Remove this unused import 'java.util.List'.(
\ No newline at end of file
diff --git a/src/medicine/.idea/sonarlint/issuestore/5/a/5aa79857db1807fe40f0941af9e17d8a19d8bc97 b/src/medicine/.idea/sonarlint/issuestore/5/a/5aa79857db1807fe40f0941af9e17d8a19d8bc97
new file mode 100644
index 00000000..5f21d348
--- /dev/null
+++ b/src/medicine/.idea/sonarlint/issuestore/5/a/5aa79857db1807fe40f0941af9e17d8a19d8bc97
@@ -0,0 +1,10 @@
+
+t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(
+S java:S106"9Replace this use of System.out or System.err by a logger.(
+A
+java:S1075"&Remove this hard-coded path-delimiter.(
+I
+java:S1128"3Remove this unused import 'java.io.BufferedReader'.(
+L
+java:S1128
+"6Remove this unused import 'java.io.InputStreamReader'.(
\ No newline at end of file
diff --git a/src/medicine/.idea/sonarlint/issuestore/5/f/5feb9f75e1bc678660918562fd0ce2745899be29 b/src/medicine/.idea/sonarlint/issuestore/5/f/5feb9f75e1bc678660918562fd0ce2745899be29
new file mode 100644
index 00000000..21a9adbf
--- /dev/null
+++ b/src/medicine/.idea/sonarlint/issuestore/5/f/5feb9f75e1bc678660918562fd0ce2745899be29
@@ -0,0 +1,23 @@
+
+J
+java:S3740"/Provide the parametrized type for this generic.(
+t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(
+S
+java:S2589"7Remove this expression which always evaluates to "true"(
+S java:S106N"9Replace this use of System.out or System.err by a logger.(
+S java:S106O"9Replace this use of System.out or System.err by a logger.(˼
+N java:S106]"9Replace this use of System.out or System.err by a logger.(ވ
+N java:S106k"9Replace this use of System.out or System.err by a logger.(
+T java:S106"9Replace this use of System.out or System.err by a logger.(
+N java:S106"9Replace this use of System.out or System.err by a logger.(ƴ7
+T java:S106"9Replace this use of System.out or System.err by a logger.(㘘
+O java:S106"9Replace this use of System.out or System.err by a logger.(¼
+N java:S106"9Replace this use of System.out or System.err by a logger.(ܝ
+T java:S106"9Replace this use of System.out or System.err by a logger.(Я
+O java:S106"9Replace this use of System.out or System.err by a logger.(
+O java:S106"9Replace this use of System.out or System.err by a logger.(ɂ
+g
+java:S1128 "LRemove this unused import 'org.springframework.cache.annotation.CacheEvict'.(
+e
+java:S1128
+"JRemove this unused import 'org.springframework.cache.annotation.CachePut'.(≠
\ No newline at end of file
diff --git a/src/medicine/.idea/sonarlint/issuestore/8/e/8ea61bcc473345da7a8363076b3ae562bc76fedc b/src/medicine/.idea/sonarlint/issuestore/8/e/8ea61bcc473345da7a8363076b3ae562bc76fedc
index ecdc35b5..aa7acc57 100644
--- a/src/medicine/.idea/sonarlint/issuestore/8/e/8ea61bcc473345da7a8363076b3ae562bc76fedc
+++ b/src/medicine/.idea/sonarlint/issuestore/8/e/8ea61bcc473345da7a8363076b3ae562bc76fedc
@@ -1,2 +1,2 @@
-{ java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(81
\ No newline at end of file
+{ java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(8é1
\ No newline at end of file
diff --git a/src/medicine/.idea/sonarlint/issuestore/e/4/e46aee6c7c512a7b48980a296fca0acf004a1907 b/src/medicine/.idea/sonarlint/issuestore/c/f/cf2b6f7a1e504e3a80407b7fb223ab50a8c9f4bf
similarity index 100%
rename from src/medicine/.idea/sonarlint/issuestore/e/4/e46aee6c7c512a7b48980a296fca0acf004a1907
rename to src/medicine/.idea/sonarlint/issuestore/c/f/cf2b6f7a1e504e3a80407b7fb223ab50a8c9f4bf
diff --git a/src/medicine/.idea/sonarlint/issuestore/e/d/edeacc9d294f3b307d4238fb3f381c6838218bb6 b/src/medicine/.idea/sonarlint/issuestore/e/d/edeacc9d294f3b307d4238fb3f381c6838218bb6
new file mode 100644
index 00000000..d4a1342d
--- /dev/null
+++ b/src/medicine/.idea/sonarlint/issuestore/e/d/edeacc9d294f3b307d4238fb3f381c6838218bb6
@@ -0,0 +1,7 @@
+
+t java:S120"ZRename this package name to match the regular expression '^[a-z_]+(\.[a-z_][a-z0-9_]*)*$'.(
+a
+java:S1128 "KRemove this unused import 'org.springframework.cache.annotation.Cacheable'.(ݺؓ
+i
+java:S1128
+"NRemove this unused import 'org.springframework.data.redis.core.RedisTemplate'.(
\ No newline at end of file
diff --git a/src/medicine/.idea/sonarlint/issuestore/index.pb b/src/medicine/.idea/sonarlint/issuestore/index.pb
index 31915749..4f78404f 100644
--- a/src/medicine/.idea/sonarlint/issuestore/index.pb
+++ b/src/medicine/.idea/sonarlint/issuestore/index.pb
@@ -1,6 +1,4 @@
-w
-Gspringboot/src/main/java/com/xht/springboot/Dao/PersonalHomeMapper.java,8\e\8ea61bcc473345da7a8363076b3ae562bc76fedc
z
Jspringboot/src/main/java/com/xht/springboot/pythonspider/PythonSpider.java,8\2\82d065e13dbb46b69838db763af0105eec47337f
{
@@ -25,8 +23,6 @@ B
test_model/pom.xml,c\5\c5247f1a7a8da981f49c6fe2b5fc0ba5e9b426bb
q
Aspringboot/src/main/java/com/xht/springboot/Entity/UserLogin.java,1\3\139a0da36daad8c438a5607ee212d1f38a505779
-B
-springboot/pom.xml,e\4\e46aee6c7c512a7b48980a296fca0acf004a1907
r
Bspringboot/src/main/java/com/xht/springboot/Dao/WebHomeMapper.java,2\a\2ad2a1260dac6c01c8b352bb0e2ca62f513676a9
p
@@ -36,4 +32,14 @@ Cspringboot/src/main/java/com/xht/springboot/Entity/UserComment.java,9\3\932ae6
q
Aspringboot/src/main/java/com/xht/springboot/Entity/UserReply.java,0\5\051eaf551b928a8ccf651611c070ebb2b8155264
l
-spring-boot-starter-cache
+
+ com.google.guava
+ guava
+ 29.0-jre
+
+
+
+ org.redisson
+ redisson
+ 3.14.1
+
+
org.springframework.boot
spring-boot-starter-aop
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Config/RedissionConfig.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Config/RedissionConfig.java
new file mode 100644
index 00000000..4609151a
--- /dev/null
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Config/RedissionConfig.java
@@ -0,0 +1,31 @@
+package com.xht.springboot.Config;
+
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.config.Config;
+import org.redisson.config.SingleServerConfig;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class RedissionConfig {
+ /*@Value("#{spring.data.redis.host}")
+ String address;
+ @Value("#{spring.data.redis.port}")
+ String port;
+ @Value("#{spring.data.redis.password}")
+ String pwd;*/
+ @Bean
+ public RedissonClient redissonClient(){
+ Config config = new Config();
+
+ SingleServerConfig singleServerConfig = config.useSingleServer();
+ singleServerConfig.setAddress("redis://192.168.225.128:6390")
+ .setPassword("molong")
+ .setDatabase(0);
+
+ RedissonClient redissonClient = Redisson.create(config);
+ return redissonClient;
+ }
+}
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Control/PersonalHomeController.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Control/PersonalHomeController.java
index 2c31426a..ce109ec7 100644
--- a/src/medicine/springboot/src/main/java/com/xht/springboot/Control/PersonalHomeController.java
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Control/PersonalHomeController.java
@@ -7,6 +7,8 @@ import com.xht.springboot.Service.PersonalHomeService;
import com.xht.springboot.Tip.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@@ -23,10 +25,32 @@ public class PersonalHomeController {
@RequestMapping("/getuserhomedata")
@ResponseBody
- public UserHome getPersonalHomeData(int uid){
+ public UserHome getUserHomeData(int uid){
return personalHomeService.getUserHomeData(uid);
}
+ @PostMapping("/postuserhomedata")
+ @ResponseBody
+ public RequestResult postUserHomeData(@RequestBody UserHome userHome){
+ RequestResult result = new RequestResult();
+ if(personalHomeService.postUserHomeData(userHome))
+ result.status = RequestResult.OK;
+ else
+ result.status = RequestResult.FAIL;
+ return result;
+ }
+
+ @PostMapping("/updateuserhomedata")
+ @ResponseBody
+ public RequestResult updateUserHomeData(@RequestBody UserHome userHome){
+ RequestResult result = new RequestResult();
+ if(personalHomeService.updateUserHomeData(userHome))
+ result.status = RequestResult.OK;
+ else
+ result.status = RequestResult.FAIL;
+ return result;
+ }
+
@RequestMapping("/getusertexts")
@ResponseBody
public List getUserTexts(int uid){
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Dao/PersonalHomeMapper.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Dao/PersonalHomeMapper.java
index 4060a8c1..b750a403 100644
--- a/src/medicine/springboot/src/main/java/com/xht/springboot/Dao/PersonalHomeMapper.java
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Dao/PersonalHomeMapper.java
@@ -12,5 +12,9 @@ public interface PersonalHomeMapper {
//根据uid查询用户详情
public UserHome findById(int id);
+ public int postUserHomeData(UserHome userHome);
+
+ public int updateUserHomeData(UserHome userHome);
+
public List findTexts(int id);
}
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Service/PersonalHomeService.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Service/PersonalHomeService.java
index f02e5135..91624e9f 100644
--- a/src/medicine/springboot/src/main/java/com/xht/springboot/Service/PersonalHomeService.java
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Service/PersonalHomeService.java
@@ -4,12 +4,17 @@ package com.xht.springboot.Service;
import com.xht.springboot.Dao.PersonalHomeMapper;
import com.xht.springboot.Entity.UserHome;
import com.xht.springboot.Entity.UserText;
+import com.xht.springboot.Utils.BloomFilterUtils;
+import org.redisson.RedissonMultiLock;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
+import java.util.concurrent.TimeUnit;
@Service
public class PersonalHomeService {
@@ -17,31 +22,100 @@ public class PersonalHomeService {
PersonalHomeMapper personalHomeMapper;
@Autowired
RedisTemplate redisTemplate;
+ @Autowired
+ BloomFilterUtils bloomFilterUtils;
+ @Autowired
+ RedissonClient redissonClient;
String userHomeDataCacheName = "userData::";
String userTxtByUidCacheName = "userTxtByUid::";
+ String userHomeDataLockHome = "userHomeDataLock";
+ String userTxtByUidLockHome = "userTxtByUidLock";
//获得用户主页数据
public UserHome getUserHomeData(int uid){
+ if(!bloomFilterUtils.queryKey(userHomeDataCacheName+uid))//布隆过滤器先过滤
+ return null;
+
UserHome userHome = (UserHome) redisTemplate.opsForValue().get(userHomeDataCacheName + uid);
if(userHome!=null)
return userHome;
else{
- synchronized (PersonalHomeService.class){
+ synchronized (PersonalHomeService.class){//双检加锁
userHome = (UserHome) redisTemplate.opsForValue().get(userHomeDataCacheName + uid);
if(userHome!=null)
return userHome;
else{
userHome = personalHomeMapper.findById(uid);
- if(userHome!=null)
- redisTemplate.opsForValue().set(userHomeDataCacheName+uid,userHome);
+
+ RLock lock = redissonClient.getLock(userHomeDataLockHome);
+ RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
+
+ redissonMultiLock.lock();//写缓存加锁
+ try {
+
+ if(userHome!=null)
+ redisTemplate.opsForValue().set(userHomeDataCacheName+uid,userHome);
+ else{//写回空值
+ redisTemplate.opsForValue().set(userHomeDataCacheName+uid,null,30, TimeUnit.SECONDS);
+ }
+
+ }catch (Exception e){
+ e.printStackTrace();
+ }finally {
+ redissonMultiLock.unlock();
+ }
+
return userHome;
}
}
}
}
+ public boolean postUserHomeData(UserHome userHome){//先更新数据库后删除缓存
+ if(personalHomeMapper.postUserHomeData(userHome)!=0){
+ RLock lock = redissonClient.getLock(userHomeDataLockHome);
+ RedissonMultiLock multiLock = new RedissonMultiLock(lock);
+
+ multiLock.lock();//写缓存加锁
+ try {
+ redisTemplate.delete(userHomeDataCacheName+userHome.getUid());
+ }catch (Exception exception){
+ exception.printStackTrace();
+ }finally {
+ multiLock.unlock();
+ }
+
+ bloomFilterUtils.putIntoBloomFilter(userHomeDataCacheName+userHome.getUid());//写入布隆过滤器
+ return true;
+ }
+ return false;
+ }
+
+ public boolean updateUserHomeData(UserHome userHome){
+ if(personalHomeMapper.updateUserHomeData(userHome)!=0){
+ RLock lock = redissonClient.getLock(userHomeDataLockHome);
+ RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
+
+ redissonMultiLock.lock();
+ try {
+ redisTemplate.delete(userHomeDataCacheName+userHome.getUid());
+ }catch (Exception exception){
+ exception.printStackTrace();
+ }finally {
+ redissonMultiLock.unlock();
+ }
+ return true;
+ }
+ return false;
+ }
+
+
+
public List getUserTexts(int uid){
+ if(!bloomFilterUtils.queryKey(userTxtByUidCacheName+uid))
+ return null;
+
List userTexts = (List) redisTemplate.opsForValue().get(userTxtByUidCacheName + uid);
if(userTexts!=null)
return userTexts;
@@ -52,8 +126,24 @@ public class PersonalHomeService {
return userTexts;
else{
userTexts = personalHomeMapper.findTexts(uid);
- if(userTexts!=null)
- redisTemplate.opsForValue().set(userTxtByUidCacheName+uid,userTexts);
+
+ RLock lock = redissonClient.getLock(userTxtByUidLockHome);
+ RedissonMultiLock redissonMultiLock = new RedissonMultiLock(lock);
+
+ redissonMultiLock.lock();
+ try {
+
+ if(userTexts!=null)
+ redisTemplate.opsForValue().set(userTxtByUidCacheName+uid,userTexts);
+ else
+ redisTemplate.opsForValue().set(userTxtByUidCacheName+uid,null,30,TimeUnit.SECONDS);
+
+ }catch (Exception e){
+ e.printStackTrace();
+ }finally {
+ redissonMultiLock.unlock();
+ }
+
return userTexts;
}
}
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Service/WebHomeService.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Service/WebHomeService.java
index 9358f17b..f3afeaa0 100644
--- a/src/medicine/springboot/src/main/java/com/xht/springboot/Service/WebHomeService.java
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Service/WebHomeService.java
@@ -105,7 +105,7 @@ public class WebHomeService {
rows = webHomeMapper.updateUserText(userText);
if(rows >= 1){
System.out.println("update text OK "+rows);
- redisTemplate.opsForValue().getAndDelete(userTxtCacheName+userText.getTextid());//先删除缓存中数据
+ redisTemplate.opsForValue().getAndDelete(userTxtCacheName+userText.getTextid());//删除缓存中数据
return true;
}else{
@@ -152,12 +152,11 @@ public class WebHomeService {
}
public boolean deleteUserComment(UserComment userComment){
- redisTemplate.opsForValue().getAndDelete(userCmtCacheName+userComment.getCommentid());
-
int rows=0;
rows = webHomeMapper.deleteUserComment(userComment);
if(rows >= 1){
System.out.println("delete comment OK "+rows);
+ redisTemplate.opsForValue().getAndDelete(userCmtCacheName+userComment.getCommentid());
return true;
}else{
return false;
@@ -165,12 +164,11 @@ public class WebHomeService {
}
public boolean updateUserComment(UserComment userComment){
- redisTemplate.opsForValue().getAndDelete(userCmtCacheName+userComment.getCommentid());
-
int rows=0;
rows = webHomeMapper.updateUserComment(userComment);
if(rows >= 1){
System.out.println("update comment OK "+rows);
+ redisTemplate.opsForValue().getAndDelete(userCmtCacheName+userComment.getCommentid());
return true;
}else{
return false;
@@ -197,12 +195,11 @@ public class WebHomeService {
}
public boolean deleteUserReply(UserReply userReply){
- redisTemplate.opsForValue().getAndDelete(userReplyCacheName+userReply.getReplyid());
-
int rows=0;
rows = webHomeMapper.deleteUserReply(userReply);
if(rows >= 1){
System.out.println("delete reply OK "+rows);
+ redisTemplate.opsForValue().getAndDelete(userReplyCacheName+userReply.getReplyid());
return true;
}else{
return false;
@@ -210,12 +207,11 @@ public class WebHomeService {
}
public boolean updateUserReply(UserReply userReply){
- redisTemplate.opsForValue().getAndDelete(userReplyCacheName+userReply.getReplyid());
-
int rows=0;
rows = webHomeMapper.updateUserReply(userReply);
if(rows >= 1){
System.out.println("update reply OK "+rows);
+ redisTemplate.opsForValue().getAndDelete(userReplyCacheName+userReply.getReplyid());
return true;
}else{
return false;
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/SpringbootApplication.java b/src/medicine/springboot/src/main/java/com/xht/springboot/SpringbootApplication.java
index 0c9057d7..7a143e77 100644
--- a/src/medicine/springboot/src/main/java/com/xht/springboot/SpringbootApplication.java
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/SpringbootApplication.java
@@ -1,18 +1,32 @@
package com.xht.springboot;
+import com.xht.springboot.Utils.BloomFilterUtils;
import com.xht.springboot.pythonspider.PythonSpider;
+import org.python.google.common.hash.BloomFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.data.redis.core.RedisTemplate;
import java.util.ArrayList;
+import java.util.Set;
@SpringBootApplication
@EnableCaching
public class SpringbootApplication {
public static void main(String[] args) {
- SpringApplication.run(SpringbootApplication.class, args);
+ ConfigurableApplicationContext applicationContext = SpringApplication.run(SpringbootApplication.class, args);
+
+ BloomFilterUtils bloomFilterUtils = applicationContext.getBean(BloomFilterUtils.class);
+ RedisTemplate redisTemplate = (RedisTemplate) applicationContext.getBean("redisTemplate");
+ Set keys = redisTemplate.keys("*");
+ System.out.println("BloomFilter: insert data");
+ for(String key : keys){
+ bloomFilterUtils.putIntoBloomFilter(key);
+ System.out.println(key);
+ }
}
}
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Utils/BloomFilterUtils.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Utils/BloomFilterUtils.java
new file mode 100644
index 00000000..1ce76416
--- /dev/null
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Utils/BloomFilterUtils.java
@@ -0,0 +1,22 @@
+package com.xht.springboot.Utils;
+
+import com.google.common.hash.BloomFilter;
+import com.google.common.hash.Funnels;
+import org.springframework.stereotype.Component;
+
+import java.nio.charset.StandardCharsets;
+
+@Component
+public class BloomFilterUtils {
+ private int bloomFilterSize = 10000;
+ private double fpp = 0.3;
+ private BloomFilter bloomFilter = BloomFilter.create(Funnels.stringFunnel(StandardCharsets.UTF_8),bloomFilterSize,fpp);
+
+ public boolean putIntoBloomFilter(String key){
+ return bloomFilter.put(key);
+ }
+
+ public boolean queryKey(String key){
+ return bloomFilter.mightContain(key);
+ }
+}
diff --git a/src/medicine/springboot/src/main/java/com/xht/springboot/Utils/MyLock.java b/src/medicine/springboot/src/main/java/com/xht/springboot/Utils/MyLock.java
new file mode 100644
index 00000000..d0c48648
--- /dev/null
+++ b/src/medicine/springboot/src/main/java/com/xht/springboot/Utils/MyLock.java
@@ -0,0 +1,4 @@
+package com.xht.springboot.Utils;
+
+public class MyLock {
+}
diff --git a/src/medicine/springboot/src/main/resources/mybatis/db1/PersonalHomeMapper.xml b/src/medicine/springboot/src/main/resources/mybatis/db1/PersonalHomeMapper.xml
index bd7897c0..bae55e36 100644
--- a/src/medicine/springboot/src/main/resources/mybatis/db1/PersonalHomeMapper.xml
+++ b/src/medicine/springboot/src/main/resources/mybatis/db1/PersonalHomeMapper.xml
@@ -8,6 +8,23 @@
select * from userdetails where uid=#{uid}
+
+ insert into userdetails(uid,registertime) values(#{uid},#{registertime})
+
+
+
+ update userdetails
+
+
+ textcounts=#{textcounts},
+
+
+ diseases=#{diseases},
+
+
+ where uid=#{uid}
+
+