SpringBoot 使用Jedis 连

时间2023-05-11 10:58:39 提问来自 Central and Western DistrictCentral 的网友 分类ChatGPT提问 浏览168 热度0
些步骤? 1. 在pom.xml文件中添加Jedis的依赖: ```xml <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> ``` 2. 配置Jedis连接池,在application.yml文件中添加如下配置: ```yaml spring: redis: host: localhost port: 6379 jedis: pool: max-active: 8 max-idle: 8 max-wait:-1 min-idle: 0 timeout : 10000 # 单位ms password : 123456 database : 0 # 数字表示使用的数据库号,默认为0号库``` 3. 编写RedisConfig类来实现Jedis连接池的初始化。 ```java @Configuration public class RedisConfig { @Bean(name="jedisPool") public JedisPool jedisPool(){ JedisPoolConfig config = new JedisPoolConfig(); config.setMaxTotal(8); config.setMaxIdle(8); config.setMaxWaitMilliSeconds(-1); config.setMinIdle(0); //根据配置文件获取相关属性值 String host = enviroment .getProperty("spring .redies .host"); int port = Integer .parseInt (enviroment .getProperty("spring .redies .port")); int timeout = Integer .parseInt (enviroment .getProperty("spring .redies .timeout")); String password= enviroment .getProperty("spring ..redies ..password"); //创建Jedids连接对象 return new JedidsPool(config,host,port,timeout,password) ; } } ``` 4、在Service层注入Jedsi连接对象,通过该对象就可以实现Redisdb的各种CRUD方法。

AI智能问答网免责声明:
以上内容除特别注明外均来源于网友提问、ChatGPT回答,权益归原著者所有,本站仅作效果演示和欣赏之用;
若以上展示有冒犯或侵害到您,敬请联系我们进行删除处理,谢谢!

上一篇 How to set pulse sha 下一篇 搜索框的用法