Skip to content

Add support for asynchronous retrieval from RedisCache #2717

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>3.2.0-SNAPSHOT</version>
<version>3.2.0-GH-2650-SNAPSHOT</version>

<name>Spring Data Redis</name>
<description>Spring Data module for Redis</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
TypeReference.of(ReactiveClusterScriptingCommands.class),
TypeReference.of(ReactiveClusterGeoCommands.class),
TypeReference.of(ReactiveClusterHyperLogLogCommands.class), TypeReference.of(ReactiveRedisOperations.class),
TypeReference.of(ReactiveRedisConnectionFactory.class),
TypeReference.of(ReactiveRedisTemplate.class), TypeReference.of(RedisOperations.class),
TypeReference.of(RedisTemplate.class), TypeReference.of(StringRedisTemplate.class),
TypeReference.of(KeyspaceConfiguration.class), TypeReference.of(MappingConfiguration.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,15 @@
import org.springframework.util.Assert;

/**
* A collection of predefined {@link BatchStrategy} implementations using {@code KEYS} or {@code SCAN} command.
* Collection of predefined {@link BatchStrategy} implementations using the Redis {@code KEYS} or {@code SCAN} command.
*
* @author Mark Paluch
* @author Christoph Strobl
* @author John Blum
* @since 2.6
*/
public abstract class BatchStrategies {

private BatchStrategies() {
// can't touch this - oh-oh oh oh oh-oh-oh
}

/**
* A {@link BatchStrategy} using a single {@code KEYS} and {@code DEL} command to remove all matching keys.
* {@code KEYS} scans the entire keyspace of the Redis database and can block the Redis worker thread for a long time
Expand Down Expand Up @@ -68,6 +65,10 @@ public static BatchStrategy scan(int batchSize) {
return new Scan(batchSize);
}

private BatchStrategies() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our source files have the following order:

  1. constructors
  2. (private) methods called from constructors
  3. static factory methods

Please revert this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. Out of curiosity, where is this documented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that we are not honoring several of these Code Style guidelines:

  • Import order (e.g. Java/Javax/Jakarta library imports first!)
  • Location of getter/setters for fields.
  • No line break after closing } and else / catch blocks.
  • Our Javadoc formatting is not consistent.
  • Etc.

// can't touch this - oh-oh oh oh oh-oh-oh
}

/**
* {@link BatchStrategy} using {@code KEYS}.
*/
Expand Down Expand Up @@ -108,9 +109,11 @@ public long cleanCache(RedisConnection connection, String name, byte[] pattern)
long count = 0;

PartitionIterator<byte[]> partitions = new PartitionIterator<>(cursor, batchSize);

while (partitions.hasNext()) {

List<byte[]> keys = partitions.next();

count += keys.size();

if (keys.size() > 0) {
Expand Down Expand Up @@ -141,7 +144,7 @@ static class PartitionIterator<T> implements Iterator<List<T>> {

@Override
public boolean hasNext() {
return iterator.hasNext();
return this.iterator.hasNext();
}

@Override
Expand All @@ -151,9 +154,10 @@ public List<T> next() {
throw new NoSuchElementException();
}

List<T> list = new ArrayList<>(size);
while (list.size() < size && iterator.hasNext()) {
list.add(iterator.next());
List<T> list = new ArrayList<>(this.size);

while (list.size() < this.size && this.iterator.hasNext()) {
list.add(this.iterator.next());
}

return list;
Expand Down
Loading