SessionRedisManage.java
2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.server.shiro.session;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.SimpleSession;
import org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO;
import java.io.*;
/**
* Created by yinbinhome@163.com on 2018/2/25.
* description:
*/
public class SessionRedisManage extends EnterpriseCacheSessionDAO {
// // 创建session,保存到数据库
// @Override
// protected Serializable doCreate(Session session) {
// Serializable sessionId = super.doCreate(session);
// RedisDb.setObject(sessionId.toString().getBytes(), sessionToByte(session));
//
// return sessionId;
// }
//
// // 获取session
// @Override
// protected Session doReadSession(Serializable sessionId) {
// // 先从缓存中获取session,如果没有再去数据库中获取
// Session session = super.doReadSession(sessionId);
// if(session == null){
// byte[] bytes = RedisDb.getObject(sessionId.toString().getBytes());
// if(bytes != null && bytes.length > 0){
// session = byteToSession(bytes);
// }
// }
// return session;
// }
//
// // 更新session的最后一次访问时间
// @Override
// protected void doUpdate(Session session) {
// super.doUpdate(session);
// RedisDb.setObject(session.getId().toString().getBytes(), sessionToByte(session));
// }
//
// // 删除session
// @Override
// protected void doDelete(Session session) {
// super.doDelete(session);
// RedisDb.delString(session.getId() + "");
// }
//
// // 把session对象转化为byte保存到redis中
// public byte[] sessionToByte(Session session){
// ByteArrayOutputStream bo = new ByteArrayOutputStream();
// byte[] bytes = null;
// try {
// ObjectOutputStream oo = new ObjectOutputStream(bo);
// oo.writeObject(session);
// bytes = bo.toByteArray();
// } catch (IOException e) {
// e.printStackTrace();
// }
// return bytes;
// }
//
// // 把byte还原为session
// public Session byteToSession(byte[] bytes){
// ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
// ObjectInputStream in;
// SimpleSession session = null;
// try {
// in = new ObjectInputStream(bi);
// session = (SimpleSession) in.readObject();
// } catch (ClassNotFoundException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
//
// return session;
// }
}