Skip to content

Commit

Permalink
fix: fix demo-redis module build error
Browse files Browse the repository at this point in the history
  • Loading branch information
helltractor committed Dec 9, 2024
1 parent 546fcc7 commit 51432b7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
Expand All @@ -14,19 +16,23 @@ public class RedisConfiguration{

final static Logger logger = LoggerFactory.getLogger(RedisConfiguration.class);

@Value("${spring.redis.host}")
private String host;

@Value("${spring.redis.port}")
private int port;

/**
* 创建RedisConnectionFactory对象,当无法使用默认的配置时,可以自定义配置
* @return
*/
@Bean
public RedisConnectionFactory redisConnectionFactory() {
return new LettuceConnectionFactory();
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(host, port);
return new LettuceConnectionFactory(configuration);
}

/**
* 创建RedisTemplate对象
* @param redisConnectionFactory
* @return
*/
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
Expand Down
4 changes: 1 addition & 3 deletions demo-redis/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ spring:
data:
redis:
host: localhost
port: 6379
password: 123456
database: 10
port: 6379

0 comments on commit 51432b7

Please sign in to comment.