午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Spring boot集成redis lettuce代碼實例

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

spring boot框架中已經集成了redis,在1.x.x的版本時默認使用的jedis客戶端,現在是2.x.x版本默認使用的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 這個依賴一定要添加 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-pool2</artifactId> </dependency>

配置文件

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

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 三级五月天 | 久久综合网址 | a毛片大片 | 成人性生交大片免费 | 色播激情 | www.狠狠撸.com| 五月天婷婷在线视频 | 黄色大片视频网站 | 成人做爰视频网站 | 一本一道久久a久久精品综合 | 国产黄色免费在线观看 | 亚洲天堂中文 | 精品亚洲一区二区三区 | 亚洲天堂手机版 | 黄色一级大片 | 青青草欧美 | 99精品欧美一区二区蜜桃免费 | 超碰97免费观看 | 中文字幕色站 | 亚洲天堂成人 | 色爽网站| 亚洲看片网站 | 国产4区 | 日本免费a级片 | 91在线观看喷潮 | 国产精品久久久国产盗摄 | 亚洲美女在线观看 | 国产精品久久久久影院老司 | 中文有码在线播放 | 种付おじさん在线播放 | www.黄色在线观看 | 日本在线观看网址 | 久久免费看视频 | 91色中文| 四虎影院永久在线 | 成人自拍网 | 久久99在线| 日韩在线 中文字幕 | 成人黄性视频 | 婷婷综合激情 | 草草在线视频 |