From c9b715a0537d76d09f2959b56efb0819d79e8dbc Mon Sep 17 00:00:00 2001 From: Mithun James <1007084+drtechie@users.noreply.github.com> Date: Sat, 7 Jun 2025 17:35:46 +0530 Subject: [PATCH] fix: save minimal data to users_ key of Redis --- .../com/iemr/mmu/utils/JwtAuthenticationUtil.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/iemr/mmu/utils/JwtAuthenticationUtil.java b/src/main/java/com/iemr/mmu/utils/JwtAuthenticationUtil.java index bce7d31b..83711a10 100644 --- a/src/main/java/com/iemr/mmu/utils/JwtAuthenticationUtil.java +++ b/src/main/java/com/iemr/mmu/utils/JwtAuthenticationUtil.java @@ -112,15 +112,21 @@ private Users fetchUserFromDB(String userId) { Users user = userLoginRepo.getUserByUserID(Long.parseLong(userId)); if (user != null) { - // Cache the user in Redis for future requests (cache for 30 minutes) - redisTemplate.opsForValue().set(redisKey, user, 30, TimeUnit.MINUTES); + Users userHash = new Users(); + userHash.setUserID(user.getUserID()); + userHash.setUserName(user.getUserName()); + + // Cache the minimal user in Redis for future requests (cache for 30 minutes) + redisTemplate.opsForValue().set(redisKey, userHash, 30, TimeUnit.MINUTES); // Log that the user has been stored in Redis logger.info("User stored in Redis with key: " + redisKey); + + return user; } else { logger.warn("User not found for userId: " + userId); } - return user; + return null; } }