免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Spring Boot 整合 Redis

簡介

Redis 是目前使用十分廣泛的內(nèi)存數(shù)據(jù)庫。Redis 比 Memcached 支持更豐富的數(shù)據(jù)類型,如 Lists, Hashes, Sets 及 Ordered Sets 等,支持?jǐn)?shù)據(jù)持久化、備份;除此之外,Redis 還支持事務(wù),HA,主從庫,同時(shí)兼具了非關(guān)系型數(shù)據(jù)庫與關(guān)系型數(shù)據(jù)的特性,有著豐富的應(yīng)用場(chǎng)景。

快速上手

1、引入依賴

<dependency>  <groupId>org.springframework.boot</groupId>  <artifactId>spring-boot-starter-data-redis</artifactId>  <version>2.1.5.RELEASE</version></dependency><dependency>  <groupId>org.apache.commons</groupId>  <artifactId>commons-pool2</artifactId>  <version>2.0</version></dependency>

2、配置文件

單機(jī)模式

# Redis數(shù)據(jù)庫索引(默認(rèn)為0)spring.redis.database=0# Redis服務(wù)器地址spring.redis.host=127.0.0.1# Redis服務(wù)器連接端口spring.redis.port=6379# Redis服務(wù)器連接密碼(默認(rèn)為空)spring.redis.password=# 連接池最大連接數(shù)(使用負(fù)值表示沒有限制)spring.redis.jedis.pool.max-active=8# 連接池最大阻塞等待時(shí)間(使用負(fù)值表示沒有限制)spring.redis.jedis.pool.max-wait=-1# 連接池中的最大空閑連接spring.redis.jedis.pool.max-idle=8# 連接池中的最小空閑連接spring.redis.jedis.pool.min-idle=0# 連接超時(shí)時(shí)間(毫秒)spring.redis.timeout=5000

哨兵模式

spring.redis.lettuce.pool.max-active=8spring.redis.lettuce.pool.max-wait=-1spring.redis.lettuce.pool.max-idle=8spring.redis.lettuce.pool.min-idle=0spring.redis.timeout=5000spring.redis.database=0spring.redis.sentinel.master=mymasterspring.redis.sentinel.nodes=127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382spring.redis.password=

3、測(cè)試

@RunWith(SpringRunner.class)@SpringBootTestpublic class RedisTests {    @Autowired    private StringRedisTemplate stringRedisTemplate;  @Test  public void contextLoads() {  }  @Test  public void setRedis(){      stringRedisTemplate.opsForValue().set("key1","張三");  }  @Test  public void getRedis(){        String s = stringRedisTemplate.opsForValue().get("key1");    System.out.println("s:    "+s);    }}

4、實(shí)現(xiàn)共享 Session

1)添加依賴

<dependency>    <groupId>org.springframework.session</groupId>    <artifactId>spring-session-data-redis</artifactId></dependency>

2)配置

@Configuration@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400)public class SessionConfig {}maxInactiveIntervalInSeconds: 設(shè)置 Session 失效時(shí)間使用 Redis Session 之后,原 Spring Boot 的 server.session.timeout 屬性不再生效。


maxInactiveIntervalInSeconds: 設(shè)置 Session 失效時(shí)間。
使用 Redis Session 之后,原 Spring Boot 的 server.session.timeout 屬性不再生效。



本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Spring Boot 使用默認(rèn)Redis客戶端操作工具lettuce時(shí),出現(xiàn)Caused by: io.lettuce.core.RedisCommandTimeoutException: Comm
【原創(chuàng)】Spring Boot集成Redis的玩法
阿里開源的這款緩存框架,用起來真優(yōu)雅!
Spring Boot(八):自定義啟動(dòng)器
4 種分布式 Session 的解決方案
面試題:你都知道哪些分布式Session實(shí)現(xiàn)方案?
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服