1

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.

springbootlearner
  • 1,220
  • 4
  • 26
  • 48

1 Answers1

0

How you are saving the data in Redis? It saves it with key. Open redis-client and perform the operation again and see if something is happening there or not. It generates a key from which you can able to view the data.

Atul
  • 3,043
  • 27
  • 39
  • Looks like its saving data.But I don't know how to view the data in Redis using redis client after save is done. – springbootlearner Oct 21 '19 at 13:05
  • Open redis-cli and use these commands to get the data. This might helps you. "keys *" this will print all keys which have data. If you want to see the data for specific data then use "hget ". – Atul Oct 21 '19 at 17:18