Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
涂亚平
/
subsidy
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit d5c90365
authored
Jan 12, 2022
by
邓敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
redis keys 优化
1 parent
b509e5d7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
6 deletions
src/main/java/com/subsidy/jobs/Scheduler.java
src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java
src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java
src/main/java/com/subsidy/util/RedisUtil.java
src/main/java/com/subsidy/jobs/Scheduler.java
View file @
d5c9036
...
@@ -72,7 +72,7 @@ public class Scheduler {
...
@@ -72,7 +72,7 @@ public class Scheduler {
*/
*/
//@Scheduled(cron = "0 39 18 * * ?")
//@Scheduled(cron = "0 39 18 * * ?")
public
void
getOprMemRecord
()
{
public
void
getOprMemRecord
()
{
Set
<
String
>
set
=
redisUtil
.
keys
(
"*memberLogin*"
);
Set
<
String
>
set
=
redisUtil
.
scan
(
"*memberLogin*"
);
if
(
set
!=
null
)
{
if
(
set
!=
null
)
{
for
(
String
str
:
set
)
{
for
(
String
str
:
set
)
{
int
result
=
(
Integer
)
redisUtil
.
get
(
str
);
int
result
=
(
Integer
)
redisUtil
.
get
(
str
);
...
...
src/main/java/com/subsidy/service/impl/AdministerServiceImpl.java
View file @
d5c9036
...
@@ -468,7 +468,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
...
@@ -468,7 +468,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
public
Future
<
ClassSummaryVO
>
summaryTask3
(
ClassSummaryVO
classSummaryVO
,
Long
classId
)
{
public
Future
<
ClassSummaryVO
>
summaryTask3
(
ClassSummaryVO
classSummaryVO
,
Long
classId
)
{
//签到总次数
//签到总次数
long
signCount
=
redisUtil
.
keys
(
"subsidySignInfo*_classId_"
+
classId
+
"*"
).
stream
().
count
();
long
signCount
=
redisUtil
.
scan
(
"subsidySignInfo*_classId_"
+
classId
+
"*"
).
stream
().
count
();
classSummaryVO
.
setAvgSignCount
(
MathUtil
.
intDivCeil
(
signCount
,
classSummaryVO
.
getMemberCount
()));
classSummaryVO
.
setAvgSignCount
(
MathUtil
.
intDivCeil
(
signCount
,
classSummaryVO
.
getMemberCount
()));
return
new
AsyncResult
<>(
classSummaryVO
);
return
new
AsyncResult
<>(
classSummaryVO
);
}
}
...
@@ -600,7 +600,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
...
@@ -600,7 +600,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
public
Future
<
ClassDetailVO
>
classDetailTask3
(
ClassDetailVO
classDetailVO
,
ClassDetailDTO
classDetailDTO
)
{
public
Future
<
ClassDetailVO
>
classDetailTask3
(
ClassDetailVO
classDetailVO
,
ClassDetailDTO
classDetailDTO
)
{
////签到次数
////签到次数
long
set
=
redisUtil
.
keys
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"memberId_"
+
classDetailVO
.
getId
()
+
"_classId_"
+
classDetailDTO
.
getId
()
+
"*"
).
stream
().
count
();
long
set
=
redisUtil
.
scan
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"memberId_"
+
classDetailVO
.
getId
()
+
"_classId_"
+
classDetailDTO
.
getId
()
+
"*"
).
stream
().
count
();
classDetailVO
.
setSignCounts
(
set
);
classDetailVO
.
setSignCounts
(
set
);
return
new
AsyncResult
<>(
classDetailVO
);
return
new
AsyncResult
<>(
classDetailVO
);
}
}
...
@@ -793,7 +793,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
...
@@ -793,7 +793,7 @@ public class AdministerServiceImpl extends ServiceImpl<AdministerMapper, Adminis
public
Future
signDetailsTask2
(
ClassSignVO
classSignVO
,
ClassDetailDTO
classDetailDTO
)
{
public
Future
signDetailsTask2
(
ClassSignVO
classSignVO
,
ClassDetailDTO
classDetailDTO
)
{
//签到
//签到
Set
<
SignInRecordDO
>
set
=
redisUtil
.
keys
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"memberId_"
+
classSignVO
.
getId
()
+
"_classId_"
+
classDetailDTO
.
getId
()
+
"*"
);
Set
<
SignInRecordDO
>
set
=
redisUtil
.
scan
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"memberId_"
+
classSignVO
.
getId
()
+
"_classId_"
+
classDetailDTO
.
getId
()
+
"*"
);
classSignVO
.
setSignCounts
(
set
.
size
());
classSignVO
.
setSignCounts
(
set
.
size
());
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
...
...
src/main/java/com/subsidy/service/impl/SignInRecordServiceImpl.java
View file @
d5c9036
...
@@ -103,7 +103,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
...
@@ -103,7 +103,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
BeanUtils
.
copyProperties
(
classSignInfoVO1
,
classSignInfoVO
);
BeanUtils
.
copyProperties
(
classSignInfoVO1
,
classSignInfoVO
);
//平均签到数 向下取整
//平均签到数 向下取整
long
signCount
=
redisUtil
.
keys
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"*_classId_"
+
classSignInfoVO
.
getClassId
()
+
"_*"
).
stream
().
count
();
long
signCount
=
redisUtil
.
scan
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"*_classId_"
+
classSignInfoVO
.
getClassId
()
+
"_*"
).
stream
().
count
();
classSignInfoVO
.
setAvgSignCount
(
MathUtil
.
intDivCeil
(
signCount
,
classSignInfoVO1
.
getMemberCount
()));
classSignInfoVO
.
setAvgSignCount
(
MathUtil
.
intDivCeil
(
signCount
,
classSignInfoVO1
.
getMemberCount
()));
return
new
AsyncResult
<>(
classSignInfoVO
);
return
new
AsyncResult
<>(
classSignInfoVO
);
}
}
...
@@ -116,7 +116,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
...
@@ -116,7 +116,7 @@ public class SignInRecordServiceImpl extends ServiceImpl<SignInRecordMapper, Sig
//获取有效课程
//获取有效课程
long
count
=
classMemberMappingMapper
.
getMemberClassCount
(
signInRecordDO
.
getMemberId
());
long
count
=
classMemberMappingMapper
.
getMemberClassCount
(
signInRecordDO
.
getMemberId
());
long
size
=
redisUtil
.
keys
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"memberId_"
+
signInRecordDO
.
getMemberId
()
+
"*_"
+
DateFormatUtil
.
format
(
new
Date
(),
"yyyyMMdd"
)+
"*"
).
stream
().
count
();
long
size
=
redisUtil
.
scan
(
RedisPrefixConstant
.
SUBSIDY_SIGN_INFO_PREFIX
+
"memberId_"
+
signInRecordDO
.
getMemberId
()
+
"*_"
+
DateFormatUtil
.
format
(
new
Date
(),
"yyyyMMdd"
)+
"*"
).
stream
().
count
();
if
(
size
!=
count
)
{
if
(
size
!=
count
)
{
signInStatusVO
.
setStatus
(
flag
);
signInStatusVO
.
setStatus
(
flag
);
...
...
src/main/java/com/subsidy/util/RedisUtil.java
View file @
d5c9036
package
com
.
subsidy
.
util
;
package
com
.
subsidy
.
util
;
import
com.google.common.collect.Sets
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.connection.jedis.JedisConnection
;
import
org.springframework.data.redis.core.BoundListOperations
;
import
org.springframework.data.redis.core.BoundListOperations
;
import
org.springframework.data.redis.core.Cursor
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.ScanOptions
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
redis.clients.jedis.ScanParams
;
import
redis.clients.jedis.commands.JedisCommands
;
import
redis.clients.jedis.commands.MultiKeyCommands
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -557,6 +567,22 @@ public class RedisUtil {
...
@@ -557,6 +567,22 @@ public class RedisUtil {
}
}
/**
/**
* 模糊查询
* @param pattern
* @return
*/
public
Set
scan
(
String
pattern
)
{
return
redisTemplate
.
execute
((
RedisCallback
<
Set
<
String
>>)
redisConnection
->
{
Set
keys
=
new
HashSet
<>();
Cursor
<
byte
[]>
cursor
=
redisConnection
.
scan
(
new
ScanOptions
.
ScanOptionsBuilder
().
match
(
pattern
).
count
(
1000
).
build
());
while
(
cursor
.
hasNext
())
{
keys
.
add
(
new
String
(
cursor
.
next
()));
}
return
keys
;
});
}
/**
* 使用Redis的消息队列
* 使用Redis的消息队列
* @param channel
* @param channel
* @param message 消息内容
* @param message 消息内容
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment