【Spring Boot】如何集成Redis,pcpop网
cpugpu芯片开发光刻机
智能终端演进
9
文件名:【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开发流程】之容器类1-介绍及常用容器类和使用Java风格迭代器进行遍历,诺基亚n83
查看 -

【Qt开发流程】之程序主窗口,武尊神(qt主窗口打开子窗口)
查看 -

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

【RabbitMQ】RabbitMQ 服务无法启动。系统出错。发生系统错误 1067。进程意外终止。,geedom
查看 -

【RabbitMQ高可用集群架构】,qq2012 beta3
查看 -

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

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

【Redis7】--3.Redis持久化,华硕a10(redis持久化rdb和aof)
查看 -

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