配置Redis集群示例:
redis:
cluster:
nodes: 172.16.25.116:6379,172.16.25.117:6379,172.16.25.118:6379,172.16.25.118:7379,172.16.25.116:7379,172.16.25.117:7379
password: Test@20211208
timeout: 20000 #redis连接超时时间(毫秒)
lettuce:
pool:
max-active: 300 # 连接池最大连接数(使用负值表示没有限制),如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)
max-idle: 80 # 连接池中的最大空闲连接 ,默认值也是8
max-wait: 100 # 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException
min-idle: 10 # 连接池中的最小空闲连接 ,默认值也是0
shutdown-timeout: 500ms
(如果有相关问题,可加微信: java2demo 进学习交流群咨询)
单机版配置:
redis:
################### redis 单机版 start ##########################
host: 192.168.180.218
port: 30011
password: Test20210501
timeout: 20000 #redis连接超时时间(毫秒)
database: 11 # DB实例(DB0 ~ DB15)
lettuce:
pool:
max-active: 300 # 连接池最大连接数(使用负值表示没有限制),如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)
max-idle: 80 # 连接池中的最大空闲连接 ,默认值也是8
max-wait: 100 # 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException
min-idle: 10 # 连接池中的最小空闲连接 ,默认值也是0
shutdown-timeout: 500ms
附件:
spring:
cloud:
nacos:
discovery:
server-addr: 192.168.180.154:30048
namespace: 6051625a-67da-417a-92c1-370a0d82123a
cluster-name: DEFAULT
config:
enabled: false
inetutils:
preferred-networks: 172.*
datasource:
druid:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://192.168.180.100:30004/postgres?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
username: postgres
password: postgres2020
initial-size: 10
max-active: 70
min-idle: 50
# initial-size: 100
# max-active: 300
# min-idle: 50
# 配置获取连接等待超时的时间
max-wait: 60000
#打开PSCache,并且指定每个连接上PSCache的大小
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
validation-query: SELECT 'x'
test-on-borrow: false
test-on-return: false
test-while-idle: true
#配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time-between-eviction-runs-millis: 60000
#配置一个连接在池中最小生存的时间,单位是毫秒
min-evictable-idle-time-millis: 300000
filters: stat,wall
# WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter
#是否启用StatFilter默认值true
web-stat-filter.enabled: true
web-stat-filter.url-pattern: /*
web-stat-filter.exclusions: "*.js , *.gif ,*.jpg ,*.png ,*.css ,*.ico , /druid/*"
web-stat-filter.session-stat-max-count: 1000
web-stat-filter.profile-enable: true
# StatViewServlet配置
#展示Druid的统计信息,StatViewServlet的用途包括:1.提供监控信息展示的html页面2.提供监控信息的JSON API
#是否启用StatViewServlet默认值true
stat-view-servlet.enabled: true
#根据配置中的url-pattern来访问内置监控页面,如果是上面的配置,内置监控页面的首页是/druid/index.html例如:
#http://110.76.43.235:9000/druid/index.html
#http://110.76.43.235:8080/mini-web/druid/index.html
stat-view-servlet.url-pattern: /druid/*
#允许清空统计数据
stat-view-servlet.reset-enable: true
stat-view-servlet.login-username: admin
stat-view-servlet.login-password: admin
#StatViewSerlvet展示出来的监控信息比较敏感,是系统运行的内部情况,如果你需要做访问控制,可以配置allow和deny这两个参数
#deny优先于allow,如果在deny列表中,就算在allow列表中,也会被拒绝。如果allow没有配置或者为空,则允许所有访问
#配置的格式
#<IP>
#或者<IP>/<SUB_NET_MASK_size>其中128.242.127.1/24
#24表示,前面24位是子网掩码,比对的时候,前面24位相同就匹配,不支持IPV6。
#stat-view-servlet.allow=
#stat-view-servlet.deny=128.242.127.1/24,128.242.128.1
# Spring监控配置,说明请参考Druid Github Wiki,配置_Druid和Spring关联监控配置
#aop-patterns= # Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔
################### mysql end ##########################
cache:
type: REDIS
redis:
cache-null-values: false
time-to-live: 600000ms
use-key-prefix: true
key-prefix: dazen
cache-names: ONE_DAY#86400,ONE_WEEK#604800,ONE_MONTH#2592000,HALF_YEAR#15768000,ONE_YEAR#31536000
redis:
################### redis 单机版 start ##########################
host: 192.168.180.218
port: 30011
password: Test20210501
timeout: 20000 #redis连接超时时间(毫秒)
database: 11 # DB实例(DB0 ~ DB15)
lettuce:
pool:
max-active: 300 # 连接池最大连接数(使用负值表示没有限制),如果赋值为-1,则表示不限制;如果pool已经分配了maxActive个jedis实例,则此时pool的状态为exhausted(耗尽)
max-idle: 80 # 连接池中的最大空闲连接 ,默认值也是8
max-wait: 100 # 等待可用连接的最大时间,单位毫秒,默认值为-1,表示永不超时。如果超过等待时间,则直接抛出JedisConnectionException
min-idle: 10 # 连接池中的最小空闲连接 ,默认值也是0
shutdown-timeout: 500ms