cannot be cast to redis.clients.jedis.JedisCommands

异常代码

        try {
            String result = redisTemplate.execute((RedisCallback) redisConnection -> {
                JedisCommands commands = (JedisCommands) redisConnection.getNativeConnection();
            });
        } catch (Exception e) {
            logger.error("set redis occured an exception", e);
        }

因为 springboot2.0中默认是使用 Lettuce来集成Redis服务,spring-boot-starter-data-redis默认只引入了 Lettuce包,并没有引入 jedis包支持。所以在我们需要手动引入 jedis的包,并排除掉 lettuce的包,pom.xml配置如下:


    org.springframework.boot
    spring-boot-starter-data-redis
    
        
            io.lettuce
            lettuce-core
        
    


    org.springframework.boot
    spring-boot-starter-test
    test


    redis.clients
    jedis

关键代码

    
        
            io.lettuce
            lettuce-core
        
    

你可能感兴趣的:(小问题)