【Spring Boot】如何集成Redis,pcpop网
cpugpu芯片开发光刻机
智能终端演进
7
文件名:【Spring Boot】如何集成Redis,pcpop网
【Spring Boot】如何集成Redis
在pom.xml文件中导入spring data redis的maven坐标。 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId></dependency> 在application.yml文件中加入redis相关配置。 spring:redis:host: 192.168.xxx.xxxport: 6379password: xxxxdatabase: 0 在Bean管理中加入配置类RedisConfig。 package com.app.studypro.config;import lombok.extern.slf4j.Slf4j;import org.springframework.cache.annotation.CachingConfigurerSupport;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.data.redis.connection.RedisConnectionFactory;import org.springframework.data.redis.core.RedisTemplate;import org.springframework.data.redis.serializer.StringRedisSerializer;/*** Redis的配置信息** @author Administrator*/@Configuration@Slf4jpublic class RedisConfig extends CachingConfigurerSupport {@Beanpublic RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();log.info("Redis的KeySerializer设置为:{}", StringRedisSerializer.class);// 默认的Key序列化器为:JdkSerializationRedisSerializer// 将key的序列化器改为StringRedisSerializer,以便可以在Redis的key设置什么就显示什么,不进行转化redisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setConnectionFactory(connectionFactory);return redisTemplate;}}
同类推荐
-

【QT】Qt控件不显示图标,y470拆机
查看 -

【Qt开发流程】之事件过滤器及sendEvent和postEvent,索爱w810c
查看 -

【R3F】0.8drei使用,lg km710
查看 -

【RK3399Pro学习笔记】七、ROS订阅者Subscriber的编程实现,索尼t90
查看 -

【RK3399Pro学习笔记】十五、ROS中launch启动文件的使用方法,quake4(ros 启动)
查看 -

【React入门实战】实现Todo代办,foxit reader 3.0
查看 -

【React学习】—SetState的使用(九),三星5508(setedit三星)
查看 -

【Redis 速通】Redis 在 Linux 上的单机服务快速搭建与部署(附完整流程步骤及命令代码),卓普zp200
查看 -

【Redis】Hash 哈希内部编码方式,phone飞车
查看