package cn.iselab.mooctest.user.configure;

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.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @Description: 作用描述
 * @Author: xuexb
 * @CreateDate: 19-1-22$ 下午3:59$
 */
@Configuration
@EnableRedisHttpSession
public class RedisSessionConfiguration {

    @Value("${website.domainName}")
    private String domainName;

    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
//        serializer.setCookieName("SESSION");
        serializer.setCookiePath("/");
        serializer.setDomainName(domainName);
//        serializer.setDomainNamePattern("^.+?\\.(\\w+\\.[a-z]+)$");
        return serializer;
    }
    @Bean
    RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new CustomSessionDefaultRedisSerializer();
    }

    // @Bean
    // RedisTemplate redisTemplate(RedisConnectionFactory factory){
    //     RedisTemplate redisTemplate = new RedisTemplate();
    //     RedisSerializer stringSerializer = new StringRedisSerializer();
    //     redisTemplate.setConnectionFactory(factory);
    //     redisTemplate.setHashValueSerializer(stringSerializer);
    //     return redisTemplate;
    // }

}
