Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
schbrain-parent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
panwangnan
schbrain-parent
Commits
0b7013c0
Commit
0b7013c0
authored
Jun 20, 2023
by
liaozan
🏀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add keys operation
parent
83008601
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
11 deletions
+32
-11
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java
...om/schbrain/framework/autoconfigure/cache/CacheUtils.java
+9
-2
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java
...framework/autoconfigure/cache/provider/CacheProvider.java
+6
-5
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java
...k/autoconfigure/cache/provider/CacheProviderDelegate.java
+2
-2
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java
...utoconfigure/cache/provider/redis/RedisCacheProvider.java
+15
-2
No files found.
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/CacheUtils.java
View file @
0b7013c0
...
...
@@ -162,10 +162,17 @@ public class CacheUtils {
}
/**
* 模糊搜索 key
* 模糊搜索 key
, 默认采用 scan 实现
*/
public
static
Set
<
String
>
keys
(
String
pattern
)
{
return
getCacheProvider
().
keys
(
pattern
);
return
keys
(
pattern
,
Long
.
MAX_VALUE
);
}
/**
* 模糊搜索 key, 默认采用 scan 实现
*/
public
static
Set
<
String
>
keys
(
String
pattern
,
long
limit
)
{
return
getCacheProvider
().
keys
(
pattern
,
limit
);
}
}
\ No newline at end of file
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProvider.java
View file @
0b7013c0
package
com.schbrain.framework.autoconfigure.cache.provider
;
import
java.time.Duration
;
import
java.util.*
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* @author zhuyf
...
...
@@ -30,11 +33,9 @@ public interface CacheProvider {
void
del
(
List
<
String
>
cacheKeys
);
/**
* 模糊搜索KEY
* @param pattern
* @return
* 模糊搜索 key, 默认采用 scan 实现
*/
Set
<
String
>
keys
(
String
pattern
);
Set
<
String
>
keys
(
String
pattern
,
long
limit
);
/**
* 缓存获取
...
...
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/CacheProviderDelegate.java
View file @
0b7013c0
...
...
@@ -63,8 +63,8 @@ public class CacheProviderDelegate implements CacheProvider {
}
@Override
public
Set
<
String
>
keys
(
String
pattern
)
{
Set
<
String
>
keys
=
getCacheProvider
().
keys
(
withKeyPrefix
(
pattern
));
public
Set
<
String
>
keys
(
String
pattern
,
long
limit
)
{
Set
<
String
>
keys
=
getCacheProvider
().
keys
(
withKeyPrefix
(
pattern
)
,
limit
);
return
StreamUtils
.
toSet
(
keys
,
this
::
removeKeyPrefix
);
}
...
...
starters/cache-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/cache/provider/redis/RedisCacheProvider.java
View file @
0b7013c0
...
...
@@ -7,8 +7,11 @@ import com.schbrain.framework.autoconfigure.cache.exception.CacheException;
import
com.schbrain.framework.autoconfigure.cache.provider.CacheProvider
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.data.redis.core.Cursor
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.ScanOptions
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.data.redis.serializer.RedisSerializer
;
import
org.springframework.util.CollectionUtils
;
import
java.nio.charset.StandardCharsets
;
...
...
@@ -74,8 +77,18 @@ public class RedisCacheProvider implements CacheProvider {
* 模糊搜索 key
*/
@Override
public
Set
<
String
>
keys
(
String
pattern
)
{
return
redisTemplate
.
keys
(
pattern
);
public
Set
<
String
>
keys
(
String
pattern
,
long
limit
)
{
Set
<
String
>
keys
=
new
HashSet
<>();
RedisSerializer
<?>
keySerializer
=
redisTemplate
.
getKeySerializer
();
ScanOptions
scanOptions
=
ScanOptions
.
scanOptions
().
match
(
pattern
).
count
(
limit
).
build
();
Cursor
<
byte
[]>
cursor
=
Objects
.
requireNonNull
(
redisTemplate
.
execute
(
connection
->
connection
.
scan
(
scanOptions
),
true
));
while
(
cursor
.
hasNext
())
{
Object
deserialized
=
keySerializer
.
deserialize
(
cursor
.
next
());
if
(
deserialized
!=
null
)
{
keys
.
add
(
deserialized
.
toString
());
}
}
return
keys
;
}
/**
...
...
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