苍穹外卖--SpringDataRedis的使用步骤实现
This commit is contained in:
@@ -86,6 +86,7 @@
|
|||||||
<artifactId>knife4j-spring-boot-starter</artifactId>
|
<artifactId>knife4j-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!--springDataRedis 起步依赖-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,3 +10,8 @@ sky:
|
|||||||
endpoint: https://oss-cn-shanghai.aliyuncs.com
|
endpoint: https://oss-cn-shanghai.aliyuncs.com
|
||||||
bucket-name: inmind-test
|
bucket-name: inmind-test
|
||||||
region: cn-shanghai
|
region: cn-shanghai
|
||||||
|
redis:
|
||||||
|
host: localhost
|
||||||
|
port: 6379
|
||||||
|
password: 123456
|
||||||
|
database: 10 #不配置的话,默认是0号数据库(redis一共有0~15,16个数据库)
|
||||||
@@ -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
|
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}
|
username: ${sky.datasource.username}
|
||||||
password: ${sky.datasource.password}
|
password: ${sky.datasource.password}
|
||||||
|
redis:
|
||||||
|
host: ${sky.redis.host}
|
||||||
|
port: ${sky.redis.port}
|
||||||
|
password: ${sky.redis.password}
|
||||||
|
database: ${sky.redis.database}
|
||||||
mybatis:
|
mybatis:
|
||||||
#mapper配置文件
|
#mapper配置文件
|
||||||
mapper-locations: classpath:mapper/*.xml
|
mapper-locations: classpath:mapper/*.xml
|
||||||
|
|||||||
Reference in New Issue
Block a user