-
Notifications
You must be signed in to change notification settings - Fork 1.2k
DATAREDIS-1151 - change clean method keys command to scan
#532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,19 +17,19 @@ | |
|
|
||
| import java.nio.charset.StandardCharsets; | ||
| import java.time.Duration; | ||
| import java.util.Collections; | ||
| import java.util.Optional; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Function; | ||
|
|
||
| import org.springframework.dao.PessimisticLockingFailureException; | ||
| import com.sun.istack.internal.Nullable; | ||
| import org.springframework.data.redis.connection.RedisConnection; | ||
| import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
| import org.springframework.data.redis.connection.RedisStringCommands.SetOption; | ||
| import org.springframework.data.redis.core.Cursor; | ||
| import org.springframework.data.redis.core.ScanOptions; | ||
| import org.springframework.data.redis.core.types.Expiration; | ||
| import org.springframework.lang.Nullable; | ||
| import org.springframework.util.Assert; | ||
|
|
||
| /** | ||
| * {@link RedisCacheWriter} implementation capable of reading/writing binary data from/to Redis in {@literal standalone} | ||
|
|
@@ -179,11 +179,14 @@ public void clean(String name, byte[] pattern) { | |
| wasLocked = true; | ||
| } | ||
|
|
||
| byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet()) | ||
| .toArray(new byte[0][]); | ||
|
|
||
| if (keys.length > 0) { | ||
| connection.del(keys); | ||
| List<byte[]> keys = new ArrayList<byte[]>(); | ||
| Cursor<byte[]> cursor = connection.scan(new ScanOptions.ScanOptionsBuilder().match(new String(pattern)).build()); | ||
| while (cursor.hasNext()) { | ||
| byte[] bytes = cursor.next(); | ||
| keys.add(bytes); | ||
| } | ||
| if (!keys.isEmpty()) { | ||
| connection.del(keys.toArray(new byte[][]{})); | ||
|
||
| } | ||
| } finally { | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use LinkedList replace ArrayList because the list may be huge.