/*
 * Copyright 2014-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package sample.config;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.session.config.annotation.web.http.EnableSpringHttpSession;
import org.springframework.session.data.redis.RedisSessionRepository;

@EnableSpringHttpSession
public class SessionConfig {

	private final RedisConnectionFactory redisConnectionFactory;

	public SessionConfig(ObjectProvider<RedisConnectionFactory> redisConnectionFactory) {
		this.redisConnectionFactory = redisConnectionFactory.getIfAvailable();
	}

	@Bean
	public RedisOperations<String, Object> sessionRedisOperations() {
		RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
		redisTemplate.setConnectionFactory(this.redisConnectionFactory);
		redisTemplate.setKeySerializer(new StringRedisSerializer());
		redisTemplate.setHashKeySerializer(new StringRedisSerializer());
		return redisTemplate;
	}

	@Bean
	public RedisSessionRepository sessionRepository(RedisOperations<String, Object> sessionRedisOperations) {
		return new RedisSessionRepository(sessionRedisOperations);
	}

}

@@ -20,10 +20,10 @@
 4-20
-19
+20
  the
@@ -640,16 +640,44 @@
 onfig;%0A%0A
+import java.time.Duration;%0A%0A
 import o
@@ -756,30 +756,324 @@
 ork.
-context.annotation.Bea
+boot.autoconfigure.session.RedisSessionProperties;%0Aimport org.springframework.boot.autoconfigure.session.SessionProperties;%0Aimport org.springframework.boot.context.properties.EnableConfigurationProperties;%0Aimport org.springframework.context.annotation.Bean;%0Aimport org.springframework.context.annotation.Configuratio
 n;%0Ai
@@ -1497,211 +1497,618 @@
 ;%0A%0A@
-EnableSpringHttpSession%0Apublic class SessionConfig %7B%0A%0A%09private final RedisConnectionFactory redisConnectionFactory;%0A%0A%09public SessionConfig(ObjectProvider%3CRedisConnectionFactory%3E redisConnectionFactory) %7B
+Configuration(proxyBeanMethods = false)%0A@EnableConfigurationProperties(RedisSessionProperties.class)%0A@EnableSpringHttpSession%0Apublic class SessionConfig %7B%0A%0A%09private final SessionProperties sessionProperties;%0A%0A%09private final RedisSessionProperties redisSessionProperties;%0A%0A%09private final RedisConnectionFactory redisConnectionFactory;%0A%0A%09public SessionConfig(SessionProperties sessionProperties, RedisSessionProperties redisSessionProperties,%0A%09%09%09ObjectProvider%3CRedisConnectionFactory%3E redisConnectionFactory) %7B%0A%09%09this.sessionProperties = sessionProperties;%0A%09%09this.redisSessionProperties = redisSessionProperties;
 %0A%09%09t
@@ -2166,19 +2166,14 @@
 .get
-IfAvailable
+Object
 ();%0A
@@ -2662,22 +2662,58 @@
 ns) %7B%0A%09%09
-return
+RedisSessionRepository sessionRepository =
  new Red
@@ -2757,14 +2757,425 @@
 tions);%0A
+%09%09Duration timeout = this.sessionProperties.getTimeout();%0A%09%09if (timeout != null) %7B%0A%09%09%09sessionRepository.setDefaultMaxInactiveInterval(timeout);%0A%09%09%7D%0A%09%09sessionRepository.setKeyNamespace(this.redisSessionProperties.getNamespace());%0A%09%09sessionRepository.setFlushMode(this.redisSessionProperties.getFlushMode());%0A%09%09sessionRepository.setSaveMode(this.redisSessionProperties.getSaveMode());%0A%09%09return sessionRepository;%0A
 %09%7D%0A%0A%7D%0A

Improve RedisSessionRepository-based sample configuration