Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in
Toggle navigation
T
tanpu-community
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
探普后端
tanpu-community
Commits
a0c1655b
Commit
a0c1655b
authored
Dec 10, 2021
by
刘基明
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
多实例记录rank日志添加分布式锁
parent
98b30d73
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
21 additions
and
7 deletions
+21
-7
RedisCache.java
...e/src/main/java/com/tanpu/community/cache/RedisCache.java
+10
-1
RankLogService.java
...main/java/com/tanpu/community/service/RankLogService.java
+0
-2
RankService.java
...rc/main/java/com/tanpu/community/service/RankService.java
+9
-2
application-test.yml
community-service/src/main/resources/application-test.yml
+2
-2
No files found.
community-service/src/main/java/com/tanpu/community/cache/RedisCache.java
View file @
a0c1655b
...
@@ -14,7 +14,7 @@ public class RedisCache {
...
@@ -14,7 +14,7 @@ public class RedisCache {
private
String
cacheName
;
private
String
cacheName
;
private
RedisHelper
redisHelper
;
private
RedisHelper
redisHelper
;
public
<
T
>
T
getObject
(
String
key
,
Integer
expireSeconds
,
Supplier
<
T
>
func
,
Class
<
T
>
clz
)
{
public
<
T
>
T
getObject
(
String
key
,
Integer
expireSeconds
,
Supplier
<
T
>
func
,
Class
<
T
>
clz
)
{
String
value
=
get
(
key
);
String
value
=
get
(
key
);
// todo 考虑缓存穿透的问题.
// todo 考虑缓存穿透的问题.
if
(
StringUtils
.
isNotBlank
(
value
))
{
if
(
StringUtils
.
isNotBlank
(
value
))
{
...
@@ -80,6 +80,15 @@ public class RedisCache {
...
@@ -80,6 +80,15 @@ public class RedisCache {
}
}
}
}
public
boolean
setIfAbsent
(
String
key
,
String
value
,
Integer
expireSeconds
)
{
key
=
cacheName
+
":"
+
key
;
if
(
expireSeconds
==
0
)
{
return
redisHelper
.
setIfAbsent
(
key
,
value
);
}
else
{
return
redisHelper
.
setIfAbsent
(
key
,
value
,
Duration
.
ofSeconds
(
expireSeconds
));
}
}
private
void
delete
(
String
key
)
{
private
void
delete
(
String
key
)
{
redisHelper
.
delete
(
key
);
redisHelper
.
delete
(
key
);
}
}
...
...
community-service/src/main/java/com/tanpu/community/service/RankLogService.java
View file @
a0c1655b
...
@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
...
@@ -11,7 +11,6 @@ import com.tanpu.community.util.BizUtils;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
...
@@ -20,7 +19,6 @@ import javax.annotation.Resource;
...
@@ -20,7 +19,6 @@ import javax.annotation.Resource;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
...
community-service/src/main/java/com/tanpu/community/service/RankService.java
View file @
a0c1655b
...
@@ -135,8 +135,15 @@ public class RankService {
...
@@ -135,8 +135,15 @@ public class RankService {
hotestThemes
=
themeAnalysDOS
.
stream
()
hotestThemes
=
themeAnalysDOS
.
stream
()
.
sorted
(
Comparator
.
comparing
(
ThemeAnalysDO:
:
getScore
).
reversed
())
.
sorted
(
Comparator
.
comparing
(
ThemeAnalysDO:
:
getScore
).
reversed
())
.
collect
(
Collectors
.
toList
());
.
collect
(
Collectors
.
toList
());
//落库
rankLogService
.
logThemeRank
(
hotestThemes
,
start
,
TimeUtils
.
calMillisTillNow
(
start
));
// 落库
try
{
redisCache
.
setIfAbsent
(
"logThemeRank"
,
"1"
,
15
);
rankLogService
.
logThemeRank
(
hotestThemes
,
start
,
TimeUtils
.
calMillisTillNow
(
start
));
}
finally
{
redisCache
.
evict
(
"logThemeRank"
);
}
}
}
...
...
community-service/src/main/resources/application-test.yml
View file @
a0c1655b
...
@@ -95,7 +95,7 @@ tmpfile:
...
@@ -95,7 +95,7 @@ tmpfile:
tanpu
:
tanpu
:
fatools
:
fatools
:
svc
:
127.0.0.1:8189
svc
:
https://testtamper.tanpuyun.com
product
:
product
:
svc
:
https://testtamper.tanpuyun.com
svc
:
https://testtamper.tanpuyun.com
jifen
:
jifen
:
...
@@ -118,7 +118,7 @@ tanpu:
...
@@ -118,7 +118,7 @@ tanpu:
#打印SQL语句
#打印SQL语句
logging
:
logging
:
level
:
level
:
com.tanpu.community.dao
:
debug
com.tanpu.community.dao
:
info
org.springframework.jdbc.core.JdbcTemplate
:
debug
org.springframework.jdbc.core.JdbcTemplate
:
debug
pagehelper
:
pagehelper
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment