集群session共享组件 Uncode-Session

码农软件 · 软件分类 · 常用工具包 · 2019-08-14 23:13:14

软件介绍

Uncode-Session

非常小巧的集群session公享组件,代码千行以内,避免使用应用容器插件的多种烦恼。

功能概述

  1. 非常小巧的集群session共享组件,类似于spring-session。

  2. 总代码不超过1000行。

  3. 易于使用和扩展。

配置

1. web.xml

<!-- 会话共享过滤器,注意放在其他filter之前 -->
<filter>
    <filter-name>SessionSharingFilter</filter-name>
    <filter-class>cn.uncode.session.SessionSharingFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SessionSharingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

2. 基于Redis的Spring配置

<!-- 配置Redis缓存池(默认基于redis实现,所以只需要配置缓存池就可以了) -->
<bean id="redisSentinelPool" class="com.ksudi.proxycache.store.redis.RedisSentinelPool">
    <property name="hosts">
        <list>
            <value>127.0.0.1:26379</value>
            <value>127.0.0.2:26379</value>
        </list>
    </property>
    <property name="auth" value="123456" />
    <property name="maxIdle" value="5" />
    <property name="maxTotal" value="20" />
    <property name="maxWaitMillis" value="10000" />
    <property name="testOnBorrow" value="true" />
</bean>

自定义扩展

1. 自定义实现类

public class CustomSessionCache implements SessionCache{

    @Override
    public void put(String sessionId, SessionMap sessionMap, int timeout) {

    }

    @Override
    public SessionMap get(String sessionId) {

    }

    @Override
    public void setMaxInactiveInterval(String sessionId, int interval) {

    }

    @Override
    public void destroy(String sessionId) {

    }
}

2. 配置管理器

<!-- 配置缓存 -->
<bean id="customSessionCache" class="cn.uncode.session.*.*.CustomSessionCache" />

<!-- 配置会话缓存管理器 -->
<bean id="sessionCacheManager" class="cn.uncode.session.data.SessionCacheManager">
    <property name="sessionCache" ref="customSessionCache" />
    <!-- 或者使用以下配置,二选一 -->
    <!--
    <property name="beanName" value="sessionCacheManager" />
    -->
</bean>

本文地址:https://codercto.com/soft/d/12385.html

Cypherpunks

Cypherpunks

Julian Assange、Jacob Appelbaum、Andy Müller-Maguhn、Jérémie Zimmermann / OR Books / 2012-11 / GBP 8.99

Cypherpunks are activists who advocate the widespread use of strong cryptography (writing in code) as a route to progressive change. Julian Assange, the editor-in-chief of and visionary behind WikiLea......一起来看看 《Cypherpunks》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器