Jedis和Lettuce的区别
- Jedis是同步的,不支持异步,Jedis客户端实例不是线程安全的,需要每个线程一个Jedis实例,所以一般通过连接池来使用Jedis;
- Lettuce是基于Netty框架的事件驱动的Redis客户端,其方法调用是异步的,Lettuce的API也是线程安全的,所以多个线程可以操作单个Lettuce连接来完成各种操作,同时Lettuce也支持连接池;
Jedis切换Lettuce
依赖修改
boot启动工程pom.xml改动
properties
<lettuce.version>5.3.6.RELEASE</lettuce.version>
<commons-pool2.version>2.8.1</commons-pool2.version>
dependencies
<dependency>
<groupId>pro.shushi.pamirs.framework</groupId>
<artifactId>pamirs-connectors-data-api</artifactId>
<exclusions>
<exclusion>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
<version>${lettuce.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>${commons-pool2.version}</version>
</dependency>
配置修改
application.yml配置修改
spring:
redis:
database: 0
host: 127.0.0.1
port: 6379
prefix: pamirs
timeout: 2000
# 可选
password: xxxxx
# 可选
# cluster:
# nodes:
# - 127.0.0.1:6379
# timeout: 2000
# max-redirects: 7
lettuce:
pool:
enable: true
max-idle: 16
min-idle: 1
max-active: 16
max-wait: 2000
Oinone社区 作者:望闲原创文章,如若转载,请注明出处:https://doc.oinone.top/backend/5158.html
访问Oinone官网:https://www.oinone.top获取数式Oinone低代码应用平台体验