I have a project generated by Jhipster, in the project I put the data to Redis using this:
import java.time.Instant;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import com.core.business.sys.model.SessionInfo;
@Slf4j
@Component
public class SessionCacheManagerImpl implements SessionCacheManager {
private final SessionService sessionService;
public SessionCacheManagerImpl(SessionService sessionService
) {
this.sessionService = sessionService;
}
@Override
@Cacheable(cacheNames = Constants.CACHE.SESSION)
public SessionInfo getSessionFromCache(String sessionId) {
return sessionService
.findOne(sessionId)
.map(session -> {
if (
!Objects.equals(session.getStatus(), STATUS.ONLINE) &&
!Objects.equals(session.getStatus(), STATUS.OFFLINE) ||
session.getExpiredTime().isBefore(Instant.now())
) {
return null;
}
return new SessionInfo()
.userAgent(session.getUserAgent())
.deviceMobileInfo(session.getDeviceMobileInfo())
.deviceId(session.getDeviceId())
.deviceIp(session.getDeviceIp())
.sessionId(session.getId());
})
.orElse(null);
}
I have checked the project, and see that Jhispter integrated this to the project.
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
</dependency>
In the second project I get data using this:
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import com.core.business.sys.model.SessionInfo;
import java.util.Optional;
@Component
@Slf4j
public class SessionCacheManagerServiceImpl implements SessionCacheManagerService {
public SessionCacheManagerServiceImpl() {}
@Override
@Cacheable(cacheNames = ConstantsCache.CACHE_NAME.SESSION)
public SessionInfo getSessionFromCache(String sessionId) {
log.info("getSessionFromCache: sessionId={}", sessionId);
return null;
}
}
But I always got null result. The second project connect to Redis using
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
I've been working on this problem 2 days, and I still don't know how to fix this problem. Can you give me some advice on this. Thanks you.