Clean up principal index immediately on delete

Previously index was cleaned up only in the Redis Keyspace Notification.
This meant there was a delay in removing the index. This does not cause
a bug since we verify sessions exist and are not expired when we look up
sessions by index. However, it could be improved.

This commit ensures that the index is cleaned up immediately on session
deletion.

Fixes gh-367
This commit is contained in:
Rob Winch
2016-02-15 08:32:31 -06:00
parent 1d0eb68f70
commit d209a10514

View File

@@ -450,6 +450,7 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
return;
}
cleanupPrincipalIndex(session);
expirationPolicy.onDelete(session);
String expireKey = getExpiredKey(session.getId());
@@ -502,10 +503,7 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
logger.debug("Publishing SessionDestroyedEvent for session " + sessionId);
}
String principal = PRINCIPAL_NAME_RESOLVER.resolvePrincipal(session);
if(principal != null) {
sessionRedisOperations.boundSetOps(getPrincipalKey(principal)).remove(sessionId);
}
cleanupPrincipalIndex(session);
if(isDeleted) {
handleDeleted(sessionId, session);
@@ -517,6 +515,17 @@ public class RedisOperationsSessionRepository implements FindByIndexNameSessionR
}
}
private void cleanupPrincipalIndex(RedisSession session) {
if(session == null) {
return;
}
String sessionId = session.getId();
String principal = PRINCIPAL_NAME_RESOLVER.resolvePrincipal(session);
if(principal != null) {
sessionRedisOperations.boundSetOps(getPrincipalKey(principal)).remove(sessionId);
}
}
public void handleCreated(Map<Object,Object> loaded, String channel) {
String id = channel.substring(channel.lastIndexOf(":") + 1);
ExpiringSession session = loadSession(id, loaded);