alibaba / jetcache

JetCache is a Java cache framework.
Apache License 2.0
4.96k stars 1.03k forks source link

报错jedis问题,不能使用lettuce吗? #890

Open zhengjiaao opened 1 month ago

zhengjiaao commented 1 month ago
<dependencies> 
   <!--redis-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-redis</artifactId>
        <version>2.3.12.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>io.lettuce</groupId>
        <artifactId>lettuce-core</artifactId>
        <version>5.3.7.RELEASE</version>
        <scope>compile</scope>
    </dependency>
    <!--redis 注解缓存:支持内存/远程redis/双级缓存(内存+远程redis)-->
    <!--<dependency>
        <groupId>com.alicp.jetcache</groupId>
        <artifactId>jetcache-starter-redis</artifactId>
        <version>2.7.5</version>
    </dependency>-->
    <dependency>
        <groupId>com.alicp.jetcache</groupId>
        <artifactId>jetcache-starter-redis-lettuce</artifactId>
        <version>2.7.5</version>
    </dependency>
</dependencies>

为什么还是报错:jedis问题,不能使用lettuce吗? Caused by: java.lang.ClassNotFoundException: redis.clients.jedis.HostAndPort Caused by: java.lang.NoClassDefFoundError: redis/clients/jedis/HostAndPort

zhengjiaao commented 1 month ago

已找到原因:这个问题是由于配置导致的,想要使用的是lettuce 客户端,而不是 Jedis 客户端。

Jedis 客户端

remote: default: type: redis # other choose:redis/redis.lettuce/redisson

lettuce 客户端

remote: default: type: redis.lettuce # other choose:redis/redis.lettuce/redisson

这个 type: redis刚开始以为是远程选址redis存储方案,而没有考虑到默认是 Jedis 客户端。

它的可读性并不像 type: redis.lettuce 配置项,导致一致以为是依赖引入问题。

zhengjiaao commented 1 month ago

建议,把 type: redis 改为 redis.jedis ,或者统一配置为type: redis,可以通过引入不同依赖,来加载redis客户端,例如:Jedis依赖 or lettuce依赖

areyouok commented 1 month ago

确实应该叫jedis的,但这样改就不兼容了。叫redis是因为很早以前只支持jedis。