【问题标题】:How to see value stored in Redis cache using Spring Boot如何使用 Spring Boot 查看存储在 Redis 缓存中的值
【发布时间】:2020-02-16 17:30:50
【问题描述】:

我有一个 Spring Boot 应用程序,它实现了 redis 缓存来cahce 方法输出。我的用例是在缓存中调用方法时存储对象列表。我的代码如下所示。

@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;
    }

这里我的意图是使用密钥 sec-ques-list 将我的 SecQuestionModel lits 存储在缓存中。它按预期工作,但是当我登录并看到 redis cahce 时,我无法使用以下命令找到这个关键对象。

LLEN sec-ques-list -> 这返回(整数)0 但我有一些对象。

我的代码是否真的将我的对象保存在 Redis 中?或者如何查看spring boot app存储的redis中的对象。

【问题讨论】:

  • 你找到答案了吗?

标签: spring-boot spring-data-redis redis-cache


【解决方案1】:

您如何在 Redis 中保存数据?它用密钥保存它。 打开 redis-client 并再次执行操作,看看那里是否发生了什么。 它会生成一个密钥,您可以从中查看数据。

【讨论】:

  • 貌似是在保存数据,但是保存完成后不知道如何使用redis客户端查看redis中的数据。
  • 打开 redis-cli 并使用这些命令获取数据。这可能会对您有所帮助。 "keys *" 这将打印所有有数据的键。如果您想查看特定数据的数据,请使用“hget ”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 2019-06-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多