Add support for clearing accounts from Redis asynchronously

This commit is contained in:
Jon Chambers 2023-07-12 17:21:23 -04:00 committed by Jon Chambers
parent 8c93368b20
commit d17c7aaba6
1 changed files with 16 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.time.Clock;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.Collections;
@ -987,4 +988,19 @@ public class AccountsManager {
});
}
}
private CompletableFuture<Void> redisDeleteAsync(final Account account) {
@SuppressWarnings("resource") final Timer.Context timerContext = redisDeleteTimer.time();
final List<String> keysToDelete = new ArrayList<>(4);
keysToDelete.add(getAccountMapKey(account.getNumber()));
keysToDelete.add(getAccountMapKey(account.getPhoneNumberIdentifier().toString()));
keysToDelete.add(getAccountEntityKey(account.getUuid()));
account.getUsernameHash().ifPresent(usernameHash -> keysToDelete.add(getUsernameHashAccountMapKey(usernameHash)));
return cacheCluster.withCluster(connection -> connection.async().del(keysToDelete.toArray(new String[0])))
.toCompletableFuture()
.thenRun(timerContext::close);
}
}