Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(session-guide): address feedback #14

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions memorystore/valkey/session/GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Building a Session Management Service on Google Cloud using Valkey, Spring Boot, and PostgreSQL

Session management is a crucial part of modern web applications, ensuring that user interactions remain consistent and secure across multiple requests. This guide outlines how to create a session management system using Spring Boot, PostgreSQL, and Valkey (or Memorystore on GCP). By using a caching layer, the application can efficiently manage user sessions while reducing database load and ensuring scalability.
Session management is a crucial part of modern web applications, ensuring that user interactions remain consistent and secure across multiple requests. This guide outlines how to create a session management system using Spring Boot, PostgreSQL, and Valkey (or Memorystore) on GCP. By using a caching layer, the application can efficiently manage user sessions while reducing database load and ensuring scalability.

## Why Session Management Matters

Expand Down Expand Up @@ -98,24 +98,16 @@ Next, add the following to the route logic in the API.
// Generate token for the user
String token = Utils.generateToken(Global.TOKEN_BYTE_LENGTH);

try {
jedis.set(token, username);
jedis.expire(token, Global.TOKEN_EXPIRATION);
} catch (Exception e) {
throw new RuntimeException("Failed to store session token", e);
}
// Store token in cache
jedis.setex(token, Global.TOKEN_EXPIRATION, username);
}
```

### Logging out a user

```java
public void logout(String token) {
try {
jedis.del(token);
} catch (Exception e) {
throw new RuntimeException("Failed to delete session token", e);
}
jedis.del(token);
}
```

Expand Down