Loading Depth Study
Preparing your workspace
Redis can act as a fast shared store for temporary state that needs to be available across application instances.
When an application runs on multiple servers, keeping session state only in one server's memory can create inconsistent behavior. Redis provides a shared location where application instances can read the same session data. Session keys should have appropriate expiration and should contain only the information needed by the application. Sensitive session identifiers and access controls must be protected carefully.
A web application running on several servers can store session data in Redis so a user can continue their session regardless of which server receives the next request.
await redis.hSet(`session:${sessionId}`, {
userId: user.id,
role: user.role
});
await redis.expire(`session:${sessionId}`, 3600);A session record is stored in Redis and automatically expires after one hour.