久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術(shù)文章
文章詳情頁

Spring boot集成redis lettuce代碼實(shí)例

瀏覽:41日期:2023-09-11 13:42:18

spring boot框架中已經(jīng)集成了redis,在1.x.x的版本時(shí)默認(rèn)使用的jedis客戶端,現(xiàn)在是2.x.x版本默認(rèn)使用的lettuce客戶端

引入依賴

<!-- spring boot redis 緩存引入 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> <version>2.0.4.RELEASE</version> </dependency>

<!-- redis依賴commons-pool 這個(gè)依賴一定要添加 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency>

配置文件

#Redis 配置#Redis服務(wù)器地址spring.redis.host=127.0.0.1#Redis服務(wù)器連接端口spring.redis.port=6379#Redis服務(wù)器連接密碼(默認(rèn)為空)spring.redis.password=123456#Redis數(shù)據(jù)庫索引(默認(rèn)為0)spring.redis.database=0##連接超時(shí)時(shí)間spring.redis.timeout=60s# 以下連接池已在SpringBoot2.0不推薦使用##連接池最大連接數(shù)(使用負(fù)值表示沒有限制)#spring.redis.jedis.pool.max-active=10##連接池最大阻塞等待時(shí)間(使用負(fù)值表示沒有限制)#spring.redis.jedis.pool.max-wait=-1ms##連接池中的最大空閑連接#spring.redis.jedis.pool.max-idle=8##連接池中的最小空閑連接#spring.redis.jedis.pool.min-idle=0# Lettuce# 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)spring.redis.lettuce.pool.max-active=8# 連接池最大阻塞等待時(shí)間(使用負(fù)值表示沒有限制)spring.redis.lettuce.pool.max-wait=10000# 連接池中的最大空閑連接spring.redis.lettuce.pool.max-idle=8# 連接池中的最小空閑連接spring.redis.lettuce.pool.min-idle=0# 關(guān)閉超時(shí)時(shí)間spring.redis.lettuce.shutdown-timeout=100

配置config

@Configuration@AutoConfigureAfter(RedisConfig.class)public class RedisConfig { // @Bean// public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {// RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();// redisTemplate.setKeySerializer(new StringRedisSerializer());// redisTemplate.setHashKeySerializer(new StringRedisSerializer());// redisTemplate.setHashValueSerializer(new StringRedisSerializer());// redisTemplate.setValueSerializer(new StringRedisSerializer());// redisTemplate.setConnectionFactory(factory);// return redisTemplate;// } @Bean public RedisTemplate<String, Serializable> redisCacheTemplate(LettuceConnectionFactory factory) { RedisTemplate<String, Serializable> template = new RedisTemplate<>(); template.setKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); template.setHashValueSerializer(new StringRedisSerializer()); template.setValueSerializer(new StringRedisSerializer()); template.setConnectionFactory(factory); return template; } @Bean public HashOperations<String, String, String> hashOperations(RedisTemplate<String, String> redisTemplate) { return redisTemplate.opsForHash(); } @Bean public ValueOperations<String, String> valueOperations(RedisTemplate<String, String> redisTemplate) { return redisTemplate.opsForValue(); } @Bean public SetOperations<String, String> setOperations(RedisTemplate<String, String> redisTemplate) { return redisTemplate.opsForSet(); } @Bean public ListOperations<String, String> listOperations(RedisTemplate<String, String> redisTemplate) { return redisTemplate.opsForList(); }}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 贵州省| 安义县| 荥阳市| 义马市| 海口市| 林西县| 赤峰市| 潞西市| 富民县| 喀什市| 夏津县| 桐城市| 西盟| 卢氏县| 平罗县| 江陵县| 双辽市| 格尔木市| 将乐县| 隆子县| 化隆| 伊春市| 宝丰县| 防城港市| 华宁县| 云安县| 四会市| 贵德县| 金山区| 定兴县| 闽清县| 抚顺县| 兰西县| 克拉玛依市| 富裕县| 湖北省| 嫩江县| 隆子县| 龙井市| 建昌县| 普安县|