I have a Spring Boot application which implemented redis cache to cahce a method output. My use case is to store list of objects when a method is called in cache. My code looks like below.
@Cacheable(value="sec-ques-list")
@Override
public List<SecQuestionModel> fetchSecQuestions() {
logger.info("fetchSecQuestions() Starts");
List<SecQuestion> secQuestionsEnty = secQuestionRepository.findAll();
List<SecQuestionModel> secQuesModelList = new ArrayList<>();
if(!CollectionUtils.isEmpty(secQuestionsEnty)){
for(SecQuestion secQuesEnty:secQuestionsEnty){
SecQuestionModel secQuesModel = new SecQuestionModel();
secQuesModel.setSecQuesId(secQuesEnty.getId().toString());
secQuesModel.setSecQuestion(secQuesEnty.getSecQuestion());
secQuesModel.setSecQuestionDesc(secQuesEnty.getSecQuestionDesc());
secQuesModel.setCreatedTime(SecQuestionUtil.convertDateTimeToString(secQuesEnty.getCreatedTime()));
secQuesModel.setUpdatedTime(SecQuestionUtil.convertDateTimeToString(secQuesEnty.getUpdatedTime()));
secQuesModel.setCreatedBy(secQuesEnty.getCreatedBy());
secQuesModel.setUpdatedBy(secQuesEnty.getUpdatedBy());
secQuesModelList.add(secQuesModel);
}
}
logger.info("fetchSecQuestions() Ends");
return secQuesModelList;
}
Here my intension is to store my lits of SecQuestionModel in cache with key sec-ques-list. Its working as expected but when I login and see redis cahce I am not able to find this key objects using below command.
LLEN sec-ques-list -> This returns (integer) 0 but I have some objects.
Is my code is actually saving my objects in Redis? or how to see the objects in redis which is stored by spring boot app.