- <dependency>
- <groupId>org.springframework.bootgroupId>
- <artifactId>spring-boot-starter-data-redisartifactId>
- dependency>
- spring:
- redis:
- host: 192.168.xxx.xxx
- port: 6379
- password: xxxx
- database: 0
- 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
- @Slf4j
- public class RedisConfig extends CachingConfigurerSupport {
-
- @Bean
- public RedisTemplate
- RedisTemplate
- log.info("Redis的KeySerializer设置为:{}", StringRedisSerializer.class);
- // 默认的Key序列化器为:JdkSerializationRedisSerializer
- // 将key的序列化器改为StringRedisSerializer,以便可以在Redis的key设置什么就显示什么,不进行转化
- redisTemplate.setKeySerializer(new StringRedisSerializer());
- redisTemplate.setConnectionFactory(connectionFactory);
- return redisTemplate;
- }
-
- }