支持自定义sessionid:MuyuRedisOperationsSessionRepository

原创
2020/11/07 01:42
阅读数 26
package org.springframework.session.data.redis;

import java.util.UUID;

import org.springframework.data.redis.core.RedisOperations;
import org.springframework.session.MapSession;
import org.springframework.session.data.redis.RedisOperationsSessionRepository;

public class SeiRedisOperationsSessionRepository extends RedisOperationsSessionRepository {
	private Integer defaultMaxInactiveInterval;
	private String router;

	public SeiRedisOperationsSessionRepository(RedisOperations<Object, Object> sessionRedisOperations) {
		super(sessionRedisOperations);
	}

	@Override
	public RedisSession createSession() {
		MapSession mapSession = new MapSession(UUID.randomUUID().toString().replace("-", "") + this.router);
		RedisSession redisSession = new RedisSession(mapSession);
		if (this.defaultMaxInactiveInterval != null) {
			redisSession.setMaxInactiveIntervalInSeconds(this.defaultMaxInactiveInterval);
		}
		return redisSession;
	}

	@Override
	public void setDefaultMaxInactiveInterval(int defaultMaxInactiveInterval) {
		this.defaultMaxInactiveInterval = defaultMaxInactiveInterval;
	}

	public void setRouter(String router) {
		this.router = router;
	}
}
	<bean id="sessionRepository" class="org.springframework.session.data.redis.SeiRedisOperationsSessionRepository">
		<constructor-arg name="sessionRedisOperations" ref="sessionRedisTemplate"/>
		<property name="defaultMaxInactiveInterval" value="7200"/>
		<property name="router" value=".tomcat2"/>
	</bean>

 

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部