Mirror username deletes unconditionally.

This commit is contained in:
Jon Chambers 2020-06-07 14:26:33 -04:00 committed by Jon Chambers
parent 1b5dc0e434
commit 1db5977e80
1 changed files with 5 additions and 9 deletions

View File

@ -119,7 +119,8 @@ public class UsernamesManager {
final String uuidMapKey = getUuidMapKey(uuid); final String uuidMapKey = getUuidMapKey(uuid);
final String usernameMapKey = getUsernameMapKey(username); final String usernameMapKey = getUsernameMapKey(username);
Optional.ofNullable(jedis.get(uuidMapKey)).ifPresent(oldUsername -> jedis.del(getUsernameMapKey(oldUsername))); final Optional<String> maybeOldUsername = Optional.ofNullable(jedis.get(uuidMapKey));
maybeOldUsername.ifPresent(oldUsername -> jedis.del(getUsernameMapKey(oldUsername)));
jedis.set(uuidMapKey, username); jedis.set(uuidMapKey, username);
jedis.set(usernameMapKey, uuid.toString()); jedis.set(usernameMapKey, uuid.toString());
@ -127,14 +128,9 @@ public class UsernamesManager {
cacheCluster.useWriteCluster(connection -> { cacheCluster.useWriteCluster(connection -> {
final RedisAdvancedClusterAsyncCommands<String, String> asyncCommands = connection.async(); final RedisAdvancedClusterAsyncCommands<String, String> asyncCommands = connection.async();
asyncCommands.get(uuidMapKey).thenAccept(oldUsername -> { maybeOldUsername.ifPresent(asyncCommands::del);
if (oldUsername != null) { asyncCommands.set(uuidMapKey, username);
asyncCommands.del(getUsernameMapKey(oldUsername)); asyncCommands.set(usernameMapKey, uuid.toString());
}
asyncCommands.set(uuidMapKey, username);
asyncCommands.set(usernameMapKey, uuid.toString());
});
}); });
} catch (JedisException e) { } catch (JedisException e) {
if (required) throw e; if (required) throw e;