支持自定义sessionid:MuyuRedisOperationsSessionRepository

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>

 

posted @ 2020-11-10 20:44  木予  阅读(201)  评论(0)    收藏  举报