package com.market.config;

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.JdkSerializationRedisSerializer;

/**
 * 专用 RedisTemplate：key/value 均使用 JDK 序列化，
 * 与其他项目（common-redis）写入格式保持一致（key 带 \xac\xed 前缀）
 */
@Configuration
public class JdkRedisConfig {

    @Bean("jdkRedisTemplate")
    public RedisTemplate<String, Object> jdkRedisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setConnectionFactory(factory);
        JdkSerializationRedisSerializer jdk = new JdkSerializationRedisSerializer();
        template.setKeySerializer(jdk);
        template.setValueSerializer(jdk);
        template.setHashKeySerializer(jdk);
        template.setHashValueSerializer(jdk);
        template.afterPropertiesSet();
        return template;
    }
}
