在项目中加入redis缓存(学习总结),金九银十旗开得胜

本文介绍了如何在Spring Boot项目中配置Redis作为缓存,包括设置密码、检查Redis服务状态、处理防火墙问题、配置RedisTemplate以及自定义KeyGenerator。通过详细步骤指导读者完成Redis的集成和配置。
摘要由CSDN通过智能技术生成

在配置文件中加入redis配置

这里要注意如果redis设置了密码要加上

spring.redis.password=*****

*****代表你redis设置的密码

如果链接不上

有可能是因为你的redis没开启

开启redis

输入命令查看开启redis没有

ps -ef | grep redis

如果还链接不上redis 可能是防火墙原因

输入命令关闭防火墙

systemctl stop firewalld

如果仍然链接不上

可能是redis端口未开放

去宝塔页面开放,这里就不做演示了

spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

spring.jackson.time-zone=GMT+8

spring.redis.host=8.130.169.21

spring.redis.port=6379

spring.redis.database= 0

spring.redis.timeout=1800000

spring.redis.password=*****

spring.redis.lettuce.pool.max-active=20

spring.redis.lettuce.pool.max-wait=-1

#最大阻塞等待时间(负数表示没限制)

spring.redis.lettuce.pool.max-idle=5

spring.redis.lettuce.pool.min-idle=0

在config包中中加入redis的配置

package com.atguigu.yygh.common.config;

import com.fasterxml.jackson.annotation.JsonAutoDetect;

import com.fasterxml.jackson.annotation.PropertyAccessor;

import com.fasterxml.jackson.databind.ObjectMapper;

import org.springframework.cache.CacheManager;

import org.springframework.cache.annotation.EnableCaching;

import org.springframework.cache.inter

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值