mm_session 1.4.6 → 1.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/store.js +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mm_session",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.8",
|
|
4
4
|
"description": "这是超级美眉session函数模块,用于web服务端session缓存",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/qiuwenwu/mm_session#readme",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"mm_cachebase": "^1.4.
|
|
33
|
+
"mm_cachebase": "^1.4.3"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/store.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
const crypto = require('crypto');
|
|
2
2
|
const CacheBase = require('mm_cachebase');
|
|
3
|
+
const {
|
|
4
|
+
type
|
|
5
|
+
} = require('os');
|
|
3
6
|
|
|
4
7
|
|
|
5
8
|
if (!$.cache) {
|
|
@@ -49,7 +52,10 @@ Store.prototype.get = async function(uuid) {
|
|
|
49
52
|
// 我们正在解码数据来自我们的srote, 我们假定它是在储存之前
|
|
50
53
|
var val = await $.cache.get(this.key + uuid);
|
|
51
54
|
if (val) {
|
|
52
|
-
|
|
55
|
+
if (typeof(val) == "string") {
|
|
56
|
+
return JSON.parse(val);
|
|
57
|
+
}
|
|
58
|
+
return val;
|
|
53
59
|
} else {
|
|
54
60
|
return null;
|
|
55
61
|
}
|
|
@@ -73,7 +79,10 @@ Store.prototype.set = async function(session, {
|
|
|
73
79
|
maxAge = 7200;
|
|
74
80
|
}
|
|
75
81
|
try {
|
|
76
|
-
|
|
82
|
+
if (typeof(session) == "object") {
|
|
83
|
+
session = JSON.stringify(session);
|
|
84
|
+
}
|
|
85
|
+
await $.cache.set(this.key + uuid, session, maxAge);
|
|
77
86
|
} catch (err) {
|
|
78
87
|
console.log('Set session error:', err);
|
|
79
88
|
}
|
|
@@ -88,4 +97,4 @@ Store.prototype.destroy = function(uuid) {
|
|
|
88
97
|
$.cache.del(this.key + uuid);
|
|
89
98
|
};
|
|
90
99
|
|
|
91
|
-
module.exports = Store;
|
|
100
|
+
module.exports = Store;
|