https://github.com/ihaolin/session
轻量的分布式会话组件(A Lightweight Distributed Session Component)
https://github.com/ihaolin/session
distributed-session redis sessionfilter
Last synced: 12 months ago
JSON representation
轻量的分布式会话组件(A Lightweight Distributed Session Component)
- Host: GitHub
- URL: https://github.com/ihaolin/session
- Owner: ihaolin
- License: mit
- Created: 2015-12-25T07:00:33.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-25T07:04:29.000Z (over 10 years ago)
- Last Synced: 2024-02-16T13:50:14.874Z (over 2 years ago)
- Topics: distributed-session, redis, sessionfilter
- Language: Java
- Homepage:
- Size: 642 KB
- Stars: 29
- Watchers: 8
- Forks: 25
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Session
轻量的分布式会话组件(A Lightweight Distribute Session Component)
---
+ 包引入(maven dependency):
```xml
me.hao0
session-redis
1.0.0
```
+ 依赖包,注意引入项目时是否需要排除(exclude if necessary):
```xml
me.hao0
session-api
1.0.0
redis.clients
jedis
2.7.2
```
+ Servlet-Filter机制(Mechanism)

+ SessionFilter如何工作(How SessionFilter Works):

+ 使用(Usage):
+ 在**web.xml**中配置Filter(Config Filter in **web.xml**):
```xml
RedisSessionFilter
me.hao0.session.redis.RedisSessionFilter
sessionCookieName
scn
maxInactiveInterval
1800
cookieContextPath
/
cookieDomain
session.com
cookieMaxAge
1800
RedisSessionFilter
/*
```
+ 在**classpath**下配置**session.properties**(Config **session.properties** in **classpath**)
```ruby
# redis model: is sentinel or not, default is not sentinel
# session.redis.mode=
# session serialize class, default is JsonSerializer
# session.serializer=
# redis host
session.redis.host=localhost
# redis port
session.redis.port=6379
# redis max connections, default is 5
# session.redis.pool.max.total=5
# redis max idle connections, default is 2
# session.redis.pool.max.idle=2
# redis session id prefix
session.redis.prefix=sid
```
+ Demo:
+ 配置**/etc/hosts**(config **/etc/hosts**):
```ruby
127.0.0.1 demo1.session.com demo2.session.com
```
+ 假如使用**nginx**作web代理,配置server(config server if use **nginx**):
```ruby
upstream session_server {
server localhost:10000;
server localhost:10001;
}
server {
listen 80;
server_name demo1.session.com demo2.session.com;
location / {
proxy_pass http://session_server;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
```
+ 运行**session-demo**(run **session-demo**):
```bash
# demo1.session.com
mvn clean jetty:run -Dmaven.test.skip -Djetty.port=10000
# demo2.session.com
mvn clean jetty:run -Dmaven.test.skip -Djetty.port=10001
```
+ 测试(Test):
+ 用户首页(user index):
```bash
http://demo1.session.com/users/index
http://demo2.session.com/users/index
```
+ 用户登录(user login):
```bash
http://demo1.session.com/users/login?username=admin&passwd=admin
http://demo2.session.com/users/login?username=admin&passwd=admin
```
+ 用户登出(user logout):
```bash
http://demo1.session.com/users/logout
http://demo2.session.com/users/logout
```
+ 使用其它的存储,如**Memcache**(Use other storage, **Memcache**, etc):
1. 继承**SessionFilter**(inherit **SessionFilter**);
2. 实现**SessionManager**(implement **SessionManager**)。
+ 相关文档(References):
+ [FilterChain机制(Filter Chain Mechanism)](http://otndnld.oracle.co.jp/document/products/as10g/101300/B25221_03/web.1013/b14426/filters.htm#BCFJCEFC);
+ 历史版本(Release History):
+ 1.0.0:
+ 基本功能实现(basic implementation)。
+ 你是好人:
+ 倘若你钱多人傻花不完,小弟乐意效劳😊,掏出你的**微信神器**做回好人吧:
+ 倘若你还不够尽兴,继续掏出你的**支付宝神器**,疯狂扫吧: