diff --git a/sky-server/pom.xml b/sky-server/pom.xml index 6172153..3a86d87 100644 --- a/sky-server/pom.xml +++ b/sky-server/pom.xml @@ -86,6 +86,7 @@ knife4j-spring-boot-starter + org.springframework.boot spring-boot-starter-data-redis diff --git a/sky-server/src/main/java/com/sky/config/RedisConfiguration.java b/sky-server/src/main/java/com/sky/config/RedisConfiguration.java new file mode 100644 index 0000000..c360172 --- /dev/null +++ b/sky-server/src/main/java/com/sky/config/RedisConfiguration.java @@ -0,0 +1,28 @@ +package com.sky.config; + +import lombok.extern.slf4j.Slf4j; +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的配置类,提供redis操作类对象,添加spring容器中,便于使用时自动注入 + */ +@Configuration +@Slf4j +public class RedisConfiguration { + + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + log.info("开始创建redis模版对象...."); + RedisTemplate redisTemplate = new RedisTemplate(); + //设置redis的连接工程 + redisTemplate.setConnectionFactory(redisConnectionFactory); + //设置redis 的key的序列化器 + redisTemplate.setKeySerializer(new StringRedisSerializer()); + return redisTemplate; + } +} diff --git a/sky-server/src/main/resources/application-dev.yml b/sky-server/src/main/resources/application-dev.yml index 134d8a8..495ea01 100644 --- a/sky-server/src/main/resources/application-dev.yml +++ b/sky-server/src/main/resources/application-dev.yml @@ -10,3 +10,8 @@ sky: endpoint: https://oss-cn-shanghai.aliyuncs.com bucket-name: inmind-test region: cn-shanghai + redis: + host: localhost + port: 6379 + password: 123456 + database: 10 #不配置的话,默认是0号数据库(redis一共有0~15,16个数据库) \ No newline at end of file diff --git a/sky-server/src/main/resources/application.yml b/sky-server/src/main/resources/application.yml index 1576b1f..a1a512f 100644 --- a/sky-server/src/main/resources/application.yml +++ b/sky-server/src/main/resources/application.yml @@ -12,7 +12,11 @@ spring: url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true username: ${sky.datasource.username} password: ${sky.datasource.password} - + redis: + host: ${sky.redis.host} + port: ${sky.redis.port} + password: ${sky.redis.password} + database: ${sky.redis.database} mybatis: #mapper配置文件 mapper-locations: classpath:mapper/*.xml