Skip to content

Commit

Permalink
Merge pull request #36867 from appsmithorg/cp/20241014-1
Browse files Browse the repository at this point in the history
  • Loading branch information
nidhi-nair authored Oct 14, 2024
2 parents cf75cf5 + b086761 commit 23d5834
Showing 1 changed file with 26 additions and 8 deletions.
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();
}
}

0 comments on commit 23d5834

Please sign in to comment.