【Spring Boot】如何集成Redis,pcpop网
cpugpu芯片开发光刻机
智能终端演进
6
文件名:【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;}}
同类推荐
-

【PXIE301-211】基于PXIE总线的16路并行LVDS数据采集、4路低速、2路隔离RS422数据处理平台,QQ音乐2009
查看 -

【Proteus仿真】【51单片机】电蒸锅温度控制系统,酷派9960(51单片机智能电饭锅控制系统)
查看 -

【QGIS入门实战精品教程】9.1:QGIS构建泰森多边形(Thiessen Polygon)实例精解,戴尔灵越14r拆机
查看 -

【Qt】QMainWidget中的栏和菜单,z60t(qt widget添加菜单栏)
查看 -

【Qt】顶层窗口和普通窗口区别以及用法,聚划算官网首页(qt 顶层窗口)
查看 -

【Qt之Quick模块】1. 概述及Quick应用程序创建流程,ipad3发布
查看 -

【Qt之绘制兔纸】,图美zoro(q版兔兔怎么画)
查看 -

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

【RabbitMQ】2、心得总结,资料汇总,s9500(rabbitmq入门案例)
查看