zoukankan      html  css  js  c++  java
  • 记录一个redis类型冲突报错:

    org.springframework.daoInvalidDataAccessApiUsageException: WRONGTYPE Operation against a key holding the wrong kind of value; nested exception is redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value

    首先我用redisTemplate.opsForValue()存了一组<k,v>,伪代码如下:

    private static final String REDIS_KEY_PRIFFIX = "string:"; 
     public void set(String val) {
            String key = REDIS_KEY_PRIFFIX +val;
            redisTemplate.opsForValue().set(key, val);
        }
    
    //测试方法
    @Test
    public void setTest1() {
        redisStringService.set("aa");
    }

    然后用redisTemplate.opsForList()存另一组<k,v>,伪代码如下

    private static final String REDIS_KEY_PREFIX = "string:";    
    public void initArticle() {
            LocalDateTime localDateTime = LocalDateTime.now();
            String localTime = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-mm-dd HH:mm"));
            long id = (new Random().nextInt(8000) + 1);
            List<Article> articles = new ArrayList<>();
            for (int i = 1; i < 6; i++) {
                Article article = new Article(
                        "1000" + i,
                        "myron" + i,
                        localTime,
                        "content" + i,
                        "title" + i, id);
                articles.add(article);
            }
            String redisKey = REDIS_KEY_PRIFIX + "aa";
            redisTemplate.opsForList().leftPushAll(redisKey,articles);
        }
    
    //测试方法
       @Test
        public void test1() {
            redisListService.initArticle();
        }

    随后报错:

    org.springframework.daoInvalidDataAccessApiUsageException: WRONGTYPE Operation against a key holding the wrong kind of value; nested exception is redis.clients.jedis.exceptions.JedisDataException: WRONGTYPE Operation against a key holding the wrong kind of value

    解决办法:

    在redis官网没找到原因,应该是类型出错了,把key删掉就ok了

  • 相关阅读:
    【转】shell处理mysql增删改查
    【转】jenkins_pipeline语法详解
    【原】Jenkins pipeline中资料总结
    【转】使用普通用户执行docker
    【原】linux两台服务器之间免密登录方法
    【原】mac电脑常用快捷建
    【原】Docker学习_Docker上传镜像至docker hub(4)
    项目实战---模拟亿邦动力网
    vue-组件之间的通信:
    vue-为什么子组件中的data选项必须是函数?
  • 原文地址:https://www.cnblogs.com/mmh760/p/13221947.html
Copyright © 2011-2022 走看看