iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >SpringBoot中对应2.0.x版本的Redis配置详解
  • 400
分享到

SpringBoot中对应2.0.x版本的Redis配置详解

2024-04-02 19:04:59 400人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

properties格式: # Redis (RedisProperties) # Redis数据库索引(默认为0) spring.redis.database=0 # Redis服

properties格式:

# Redis (RedisProperties)
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器地址
spring.redis.host=localhost
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.passWord=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=8
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=8
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=5000

yml格式:

目前版本,简单的连接redis配置文件内容如下:

spring:
  redis:
    database: 0
    host: 127.0.0.1
    port: 6379
    password: 12345
    jedis.pool.max-idle: 100
    jedis.pool.max-wait: -1ms
    jedis.pool.min-idle: 2
    timeout: 2000ms

依赖:

<!--用于redis数据库连接-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

如果是使用 lettuce客户端进行连接(我个人非常推荐使用小白菜,毕竟SpringBoot 2.X 之后底层已经不再是jedis了,是lettuce):

yml格式

spring:
  redis:
    lettuce:
      pool:
        #连接池最大连接数 使用负值代表无限制 默认为8
        max-active: 10
        #最大空闲连接 默认8
        max-idle: 10
        #最小空闲连接 默认0
        min-idle: 1
    host: 127.0.0.1
    password: 12345
    port: 6379
    database: 2
    timeout: 2000ms

 propertie格式

# Redis数据库索引(默认为0)
spring.redis.database=2
# Redis服务器地址
spring.redis.host=127.0.0.1
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=12345
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.lettuce.pool.max-active=200
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.lettuce.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.lettuce.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.lettuce.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=1000

依赖(如果不使用连接池pool,就不需要加第二个依赖,我推荐还是使用上):

        <!--用于redis数据库连接-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <!--用于redis lettuce 连接池pool使用-->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
        </dependency>

到此这篇关于SpringBoot中对应2.0.x版本的Redis配置详解的文章就介绍到这了,更多相关SpringBoot Redis配置内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

--结束END--

本文标题: SpringBoot中对应2.0.x版本的Redis配置详解

本文链接: https://www.lsjlt.com/news/152422.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作