Skip to content
Merged
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import io.mongock.api.annotations.RollbackExecution;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.core.ReactiveRedisOperations;
import org.springframework.data.redis.core.ScanOptions;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.nio.ByteBuffer;

@Slf4j
@ChangeUnit(order = "063", id = "reset_session_oauth2_spring_3_3")
Expand All @@ -16,12 +21,25 @@ public void rollbackExecution() {}

@Execution
public void execute(
@Qualifier("reactiveRedisTemplate") final ReactiveRedisTemplate<String, Object> reactiveRedisTemplate) {
reactiveRedisTemplate
.getConnectionFactory()
.getReactiveConnection()
.serverCommands()
.flushDb()
.block();
@Qualifier("reactiveRedisOperations") ReactiveRedisOperations<String, Object> reactiveRedisOperations) {
scanForKeysAcrossCluster(reactiveRedisOperations, "*").block();
}

private Mono<Void> scanForKeysAcrossCluster(
ReactiveRedisOperations<String, Object> reactiveRedisOperations, String pattern) {
return reactiveRedisOperations
.execute(connection -> {
Flux<ByteBuffer> scanFlux = connection
.keyCommands()
.scan(ScanOptions.scanOptions()
.match(pattern)
.count(1000)
.build());
return scanFlux.flatMap(scannedKey -> {
return connection.keyCommands().del(scannedKey);
})
.then();
})
.then();
}
}