SpringBoot项目使用Redis

pom.xml

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>

application.properties

#redis 配置
spring.redis.host=192.168.122.128
spring.redis.password=123456
spring.redis.port=6379
spring.redis.timeout=3000
spring.redis.pool.max-active=8
spring.redis.pool.max-idle=8
spring.redis.pool.max-wait=-1
spring.redis.pool.min-idle=0

RedisConfig.java

@Configuration
public class RedisConfig {
    @Autowired
    private RedisConnectionFactory factory;

    @Bean
    public RedisTemplate<String, Object> redisTemplate() {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        redisTemplate.setConnectionFactory(factory);
        return redisTemplate;
    }

    @Bean
    public StringRedisTemplate stingRedisTemplate() {
        StringRedisTemplate template = new StringRedisTemplate(factory);
        template.setDefaultSerializer(new StringRedisSerializer());
        return template;
    }

}

猜你喜欢

转载自blog.csdn.net/qq_31024823/article/details/81561377
今日推荐