Skip to content

Commit

Permalink
Merge pull request jcoleman#64 from heikkipora/master
Browse files Browse the repository at this point in the history
Fix duplicating jvmRoute prefixes on sessionIds.
  • Loading branch information
jcoleman committed Apr 8, 2015
2 parents f76bff3 + 01ff25b commit d166222
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ example-app/build/*
example-app/.gradle/*
.DS_Store
.rspec
*.iml
.idea/*
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,13 @@ public Session createSession(String requestedSessionId) {

// Ensure generation of a unique session identifier.
if (null != requestedSessionId) {
sessionId = requestedSessionId;
if (jvmRoute != null) {
sessionId += '.' + jvmRoute;
}
sessionId = sessionIdWithJvmRoute(requestedSessionId, jvmRoute);
if (jedis.setnx(sessionId.getBytes(), NULL_SESSION) == 0L) {
sessionId = null;
}
} else {
do {
sessionId = generateSessionId();
if (jvmRoute != null) {
sessionId += '.' + jvmRoute;
}
sessionId = sessionIdWithJvmRoute(generateSessionId(), jvmRoute);
} while (jedis.setnx(sessionId.getBytes(), NULL_SESSION) == 0L); // 1 = key set; 0 = key already existed
}

Expand Down Expand Up @@ -402,6 +396,14 @@ This ensures that the save(session) at the end of the request
return session;
}

private String sessionIdWithJvmRoute(String sessionId, String jvmRoute) {
if (jvmRoute != null) {
String jvmRoutePrefix = '.' + jvmRoute;
return sessionId.endsWith(jvmRoutePrefix) ? sessionId : sessionId + jvmRoutePrefix;
}
return sessionId;
}

@Override
public Session createEmptySession() {
return new RedisSession(this);
Expand Down

0 comments on commit d166222

Please sign in to comment.