package cn.teammodel.config.redis;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {



    @Bean
    public LettuceConnectionFactory dbConnectionFactory() {
        RedisStandaloneConfiguration config = new RedisStandaloneConfiguration("52.130.252.100", 6379);
        config.setDatabase(8); // 设置数据库编号为8
        config.setPassword("habook");
        return new LettuceConnectionFactory(config);
    }


    @Bean
    public StringRedisTemplate db1Template(LettuceConnectionFactory dbConnectionFactory) {
        StringRedisTemplate template = new StringRedisTemplate();
        template.setConnectionFactory(dbConnectionFactory);
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }
}
