Authored by 李奇

Merge remote-tracking branch 'origin/feature/remove-memcached' into feature/docker

@@ -81,13 +81,6 @@ module.exports = { @@ -81,13 +81,6 @@ module.exports = {
81 }, 81 },
82 useOneapm: false, 82 useOneapm: false,
83 useCache: true, 83 useCache: true,
84 - memcache: {  
85 - master: ['127.0.0.1:11211'],  
86 - slave: ['127.0.0.1:11211'],  
87 - session: ['127.0.0.1:11211'],  
88 - timeout: 1000,  
89 - retries: 0  
90 - },  
91 interfaceShunt: { 84 interfaceShunt: {
92 open: false 85 open: false
93 }, 86 },
@@ -152,8 +145,8 @@ module.exports = { @@ -152,8 +145,8 @@ module.exports = {
152 apiCache: { 145 apiCache: {
153 cache: true 146 cache: true
154 }, 147 },
  148 + sessionRedisPrefix: 'yohobuy_session:',
155 zookeeperServer: '192.168.102.168:2188', 149 zookeeperServer: '192.168.102.168:2188',
156 - sessionMemcachedPrefix: 'yohobuy_session:',  
157 redis: { 150 redis: {
158 connect: { 151 connect: {
159 host: '192.168.102.49', 152 host: '192.168.102.49',
@@ -204,19 +197,6 @@ if (isProduction) { @@ -204,19 +197,6 @@ if (isProduction) {
204 unionApi: 'http://union.yoho.cn/', 197 unionApi: 'http://union.yoho.cn/',
205 yohoNowApi: 'http://new.yohoboys.com/', 198 yohoNowApi: 'http://new.yohoboys.com/',
206 }, 199 },
207 - memcache: {  
208 - master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111',  
209 - 'memcache3.yohoops.org:12111', 'memcache4.yohoops.org:12111'],  
210 - slave: ['memcache1.yohoops.org:12112', 'memcache2.yohoops.org:12112',  
211 - 'memcache3.yohoops.org:12112', 'memcache4.yohoops.org:12112'],  
212 - session: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111',  
213 - 'memcache3.yohoops.org:12111', 'memcache4.yohoops.org:12111'],  
214 - poolSize: 100,  
215 - reconnect: 5000,  
216 - timeout: 300,  
217 - retries: 0,  
218 - retry: 3000  
219 - },  
220 useOneapm: true, 200 useOneapm: true,
221 useCache: true, 201 useCache: true,
222 interfaceShunt: { 202 interfaceShunt: {
@@ -265,13 +245,6 @@ if (isProduction) { @@ -265,13 +245,6 @@ if (isProduction) {
265 }, 245 },
266 useOneapm: true, 246 useOneapm: true,
267 useCache: true, 247 useCache: true,
268 - memcache: {  
269 - master: ['127.0.0.1:12111', '127.0.0.1:12111', '127.0.0.1:12111'],  
270 - slave: ['127.0.0.1:12112', '127.0.0.1:12112', '127.0.0.1:12112'],  
271 - session: ['120.0.0.1:12111', '127.0.0.1:12111', '127.0.0.1:12111'],  
272 - timeout: 1000,  
273 - retries: 0  
274 - },  
275 redis: { 248 redis: {
276 connect: { 249 connect: {
277 host: '192.168.104.32', 250 host: '192.168.104.32',
1 -const config = global.yoho.config;  
2 -const memcachedSession = require('yoho-express-session');  
3 const _ = require('lodash'); 1 const _ = require('lodash');
4 const uuid = require('uuid'); 2 const uuid = require('uuid');
5 - 3 +const config = global.yoho.config;
  4 +const session = require('yoho-express-session');
6 const cookieSession = require('client-sessions'); 5 const cookieSession = require('client-sessions');
7 -const memcached = require('connect-memcached');  
8 -const MemcachedStore = memcached(memcachedSession); 6 +const redis = require('connect-redis');
  7 +const RedisStore = redis(session);
9 8
10 /** 9 /**
11 - * 该中间件主要把 express-session 和 client-session 集中起来处理,如果 memcached 出错了,使用 cookie session 10 + * 该中间件主要把 express-session 和 client-session 集中起来处理,如果 redis 出错了,使用 cookie session
12 * @param opts.backSession cookieSession 的键名 11 * @param opts.backSession cookieSession 的键名
13 * @returns {function(*=, *=, *)} 12 * @returns {function(*=, *=, *)}
14 */ 13 */
15 function yohoSession(opts) { 14 function yohoSession(opts) {
16 return (req, res, next) => { 15 return (req, res, next) => {
17 - let notUseMemcached = _.get(req.app.locals.pc, 'session.removeMemcached', false); 16 + let notUseRedis = _.get(req.app.locals.pc, 'session.removeRedis', false);
18 17
19 opts.backSession = opts.backSession || 'session2'; 18 opts.backSession = opts.backSession || 'session2';
20 -  
21 - if (req.session && !notUseMemcached) { 19 + if (req.session && !notUseRedis) {
22 req.sessionError = false; 20 req.sessionError = false;
23 } else { 21 } else {
24 // 重建 session 22 // 重建 session
@@ -26,8 +24,8 @@ function yohoSession(opts) { @@ -26,8 +24,8 @@ function yohoSession(opts) {
26 req.sessionError = true; 24 req.sessionError = true;
27 25
28 req.sessionID = req.sessionID || uuid.v4(); 26 req.sessionID = req.sessionID || uuid.v4();
29 - req.session = new memcachedSession.Session(req, req[opts.backSession].sessionBack);  
30 - req.session.cookie = new memcachedSession.Cookie({ 27 + req.session = new session.Session(req, req[opts.backSession].sessionBack);
  28 + req.session.cookie = new session.Cookie({
31 domain: config.cookieDomain, 29 domain: config.cookieDomain,
32 httpOnly: false 30 httpOnly: false
33 }); 31 });
@@ -51,7 +49,7 @@ function yohoSession(opts) { @@ -51,7 +49,7 @@ function yohoSession(opts) {
51 } 49 }
52 50
53 module.exports = (app) => { 51 module.exports = (app) => {
54 - app.use(memcachedSession({ // eslint-disable-line 52 + app.use(session({ // eslint-disable-line
55 proxy: true, 53 proxy: true,
56 resave: false, 54 resave: false,
57 saveUninitialized: true, 55 saveUninitialized: true,
@@ -65,12 +63,10 @@ module.exports = (app) => { @@ -65,12 +63,10 @@ module.exports = (app) => {
65 getid() { 63 getid() {
66 return uuid.v4(); 64 return uuid.v4();
67 }, 65 },
68 - store: new MemcachedStore({  
69 - hosts: config.memcache.session,  
70 - prefix: config.sessionMemcachedPrefix,  
71 - reconnect: 5000,  
72 - timeout: 1000,  
73 - retries: 0 66 + store: new RedisStore({
  67 + port: config.redis.port,
  68 + host: config.redis.connect.host,
  69 + prefix: config.sessionRedisPrefix
74 }) 70 })
75 })); 71 }));
76 72
@@ -28,8 +28,8 @@ @@ -28,8 +28,8 @@
28 "client-sessions": "^0.7.0", 28 "client-sessions": "^0.7.0",
29 "clipboard": "^1.7.1", 29 "clipboard": "^1.7.1",
30 "compression": "^1.6.2", 30 "compression": "^1.6.2",
31 - "connect-memcached": "^0.2.0",  
32 "connect-multiparty": "^2.0.0", 31 "connect-multiparty": "^2.0.0",
  32 + "connect-redis": "^3.3.3",
33 "cookie-parser": "^1.4.3", 33 "cookie-parser": "^1.4.3",
34 "csurf": "^1.9.0", 34 "csurf": "^1.9.0",
35 "dnscache": "^1.0.1", 35 "dnscache": "^1.0.1",
@@ -57,7 +57,7 @@ @@ -57,7 +57,7 @@
57 "urlencode": "^1.1.0", 57 "urlencode": "^1.1.0",
58 "uuid": "^2.0.2", 58 "uuid": "^2.0.2",
59 "yoho-express-session": "^2.0.0", 59 "yoho-express-session": "^2.0.0",
60 - "yoho-node-lib": "=0.6.3", 60 + "yoho-node-lib": "=0.6.5",
61 "yoho-zookeeper": "^1.0.8" 61 "yoho-zookeeper": "^1.0.8"
62 }, 62 },
63 "devDependencies": { 63 "devDependencies": {
@@ -1623,12 +1623,6 @@ connect-history-api-fallback@^1.3.0: @@ -1623,12 +1623,6 @@ connect-history-api-fallback@^1.3.0:
1623 version "1.5.0" 1623 version "1.5.0"
1624 resolved "http://npm.yohops.com/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#b06873934bc5e344fef611a196a6faae0aee015a" 1624 resolved "http://npm.yohops.com/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#b06873934bc5e344fef611a196a6faae0aee015a"
1625 1625
1626 -connect-memcached@^0.2.0:  
1627 - version "0.2.0"  
1628 - resolved "http://npm.yohops.com/connect-memcached/-/connect-memcached-0.2.0.tgz#64907180324e117d9e8f299c994c0cb03d5020cf"  
1629 - dependencies:  
1630 - memcached "2.2.x"  
1631 -  
1632 connect-multiparty@^2.0.0: 1626 connect-multiparty@^2.0.0:
1633 version "2.1.0" 1627 version "2.1.0"
1634 resolved "http://npm.yohops.com/connect-multiparty/-/connect-multiparty-2.1.0.tgz#b562232ea638e13222d87e7b67be437f7ad89814" 1628 resolved "http://npm.yohops.com/connect-multiparty/-/connect-multiparty-2.1.0.tgz#b562232ea638e13222d87e7b67be437f7ad89814"
@@ -1638,9 +1632,12 @@ connect-multiparty@^2.0.0: @@ -1638,9 +1632,12 @@ connect-multiparty@^2.0.0:
1638 qs "~6.5.1" 1632 qs "~6.5.1"
1639 type-is "~1.6.15" 1633 type-is "~1.6.15"
1640 1634
1641 -connection-parse@0.0.x:  
1642 - version "0.0.7"  
1643 - resolved "http://npm.yohops.com/connection-parse/-/connection-parse-0.0.7.tgz#18e7318aab06a699267372b10c5226d25a1c9a69" 1635 +connect-redis@^3.3.3:
  1636 + version "3.3.3"
  1637 + resolved "http://npm.yohops.com/connect-redis/-/connect-redis-3.3.3.tgz#0fb8f370192f62da75ec7a9507807599fbe15b37"
  1638 + dependencies:
  1639 + debug "^3.1.0"
  1640 + redis "^2.1.0"
1644 1641
1645 console-browserify@^1.1.0: 1642 console-browserify@^1.1.0:
1646 version "1.1.0" 1643 version "1.1.0"
@@ -3390,13 +3387,6 @@ hasha@^2.2.0: @@ -3390,13 +3387,6 @@ hasha@^2.2.0:
3390 is-stream "^1.0.1" 3387 is-stream "^1.0.1"
3391 pinkie-promise "^2.0.0" 3388 pinkie-promise "^2.0.0"
3392 3389
3393 -hashring@3.2.x:  
3394 - version "3.2.0"  
3395 - resolved "http://npm.yohops.com/hashring/-/hashring-3.2.0.tgz#fda4efde8aa22cdb97fb1d2a65e88401e1c144ce"  
3396 - dependencies:  
3397 - connection-parse "0.0.x"  
3398 - simple-lru-cache "0.0.x"  
3399 -  
3400 hawk@3.1.3, hawk@~3.1.3: 3390 hawk@3.1.3, hawk@~3.1.3:
3401 version "3.1.3" 3391 version "3.1.3"
3402 resolved "http://npm.yohops.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4" 3392 resolved "http://npm.yohops.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
@@ -4015,12 +4005,6 @@ isstream@0.1.x, isstream@~0.1.2: @@ -4015,12 +4005,6 @@ isstream@0.1.x, isstream@~0.1.2:
4015 version "0.1.2" 4005 version "0.1.2"
4016 resolved "http://npm.yohops.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" 4006 resolved "http://npm.yohops.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
4017 4007
4018 -jackpot@>=0.0.6:  
4019 - version "0.0.6"  
4020 - resolved "http://npm.yohops.com/jackpot/-/jackpot-0.0.6.tgz#3cff064285cbf66f4eab2593c90bce816a821849"  
4021 - dependencies:  
4022 - retry "0.6.0"  
4023 -  
4024 jpeg-js@0.0.4: 4008 jpeg-js@0.0.4:
4025 version "0.0.4" 4009 version "0.0.4"
4026 resolved "http://npm.yohops.com/jpeg-js/-/jpeg-js-0.0.4.tgz#06aaf47efec7af0b1924a59cd695a6d2b5ed870e" 4010 resolved "http://npm.yohops.com/jpeg-js/-/jpeg-js-0.0.4.tgz#06aaf47efec7af0b1924a59cd695a6d2b5ed870e"
@@ -4641,13 +4625,6 @@ mem@^1.1.0: @@ -4641,13 +4625,6 @@ mem@^1.1.0:
4641 dependencies: 4625 dependencies:
4642 mimic-fn "^1.0.0" 4626 mimic-fn "^1.0.0"
4643 4627
4644 -memcached@2.2.x, memcached@^2.2.2:  
4645 - version "2.2.2"  
4646 - resolved "http://npm.yohops.com/memcached/-/memcached-2.2.2.tgz#68f86ccfd84bcf93cc25ed46d6d7fc0c7521c9d5"  
4647 - dependencies:  
4648 - hashring "3.2.x"  
4649 - jackpot ">=0.0.6"  
4650 -  
4651 memory-fs@^0.4.0, memory-fs@~0.4.1: 4628 memory-fs@^0.4.0, memory-fs@~0.4.1:
4652 version "0.4.1" 4629 version "0.4.1"
4653 resolved "http://npm.yohops.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552" 4630 resolved "http://npm.yohops.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
@@ -6644,7 +6621,7 @@ redis-parser@^2.6.0: @@ -6644,7 +6621,7 @@ redis-parser@^2.6.0:
6644 version "2.6.0" 6621 version "2.6.0"
6645 resolved "http://npm.yohops.com/redis-parser/-/redis-parser-2.6.0.tgz#52ed09dacac108f1a631c07e9b69941e7a19504b" 6622 resolved "http://npm.yohops.com/redis-parser/-/redis-parser-2.6.0.tgz#52ed09dacac108f1a631c07e9b69941e7a19504b"
6646 6623
6647 -redis@^2.7.1: 6624 +redis@^2.1.0, redis@^2.7.1, redis@^2.8.0:
6648 version "2.8.0" 6625 version "2.8.0"
6649 resolved "http://npm.yohops.com/redis/-/redis-2.8.0.tgz#202288e3f58c49f6079d97af7a10e1303ae14b02" 6626 resolved "http://npm.yohops.com/redis/-/redis-2.8.0.tgz#202288e3f58c49f6079d97af7a10e1303ae14b02"
6650 dependencies: 6627 dependencies:
@@ -6948,10 +6925,6 @@ ret@~0.1.10: @@ -6948,10 +6925,6 @@ ret@~0.1.10:
6948 version "0.1.15" 6925 version "0.1.15"
6949 resolved "http://npm.yohops.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" 6926 resolved "http://npm.yohops.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
6950 6927
6951 -retry@0.6.0:  
6952 - version "0.6.0"  
6953 - resolved "http://npm.yohops.com/retry/-/retry-0.6.0.tgz#1c010713279a6fd1e8def28af0c3ff1871caa537"  
6954 -  
6955 rewire@^2.5.1: 6928 rewire@^2.5.1:
6956 version "2.5.2" 6929 version "2.5.2"
6957 resolved "http://npm.yohops.com/rewire/-/rewire-2.5.2.tgz#6427de7b7feefa7d36401507eb64a5385bc58dc7" 6930 resolved "http://npm.yohops.com/rewire/-/rewire-2.5.2.tgz#6427de7b7feefa7d36401507eb64a5385bc58dc7"
@@ -7189,10 +7162,6 @@ signal-exit@^3.0.0: @@ -7189,10 +7162,6 @@ signal-exit@^3.0.0:
7189 version "3.0.2" 7162 version "3.0.2"
7190 resolved "http://npm.yohops.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" 7163 resolved "http://npm.yohops.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
7191 7164
7192 -simple-lru-cache@0.0.x:  
7193 - version "0.0.2"  
7194 - resolved "http://npm.yohops.com/simple-lru-cache/-/simple-lru-cache-0.0.2.tgz#d59cc3a193c1a5d0320f84ee732f6e4713e511dd"  
7195 -  
7196 sitemap@^1.12.1: 7165 sitemap@^1.12.1:
7197 version "1.13.0" 7166 version "1.13.0"
7198 resolved "http://npm.yohops.com/sitemap/-/sitemap-1.13.0.tgz#569cbe2180202926a62a266cd3de09c9ceb43f83" 7167 resolved "http://npm.yohops.com/sitemap/-/sitemap-1.13.0.tgz#569cbe2180202926a62a266cd3de09c9ceb43f83"
@@ -8701,9 +8670,9 @@ yoho-jquery@^1.12.4: @@ -8701,9 +8670,9 @@ yoho-jquery@^1.12.4:
8701 version "1.12.4" 8670 version "1.12.4"
8702 resolved "http://npm.yohops.com/yoho-jquery/-/yoho-jquery-1.12.4.tgz#22499b325f293ee8b1d60559777348156494926d" 8671 resolved "http://npm.yohops.com/yoho-jquery/-/yoho-jquery-1.12.4.tgz#22499b325f293ee8b1d60559777348156494926d"
8703 8672
8704 -yoho-node-lib@=0.6.3:  
8705 - version "0.6.3"  
8706 - resolved "http://npm.yohops.com/yoho-node-lib/-/yoho-node-lib-0.6.3.tgz#d17a18a07127a961169746fe4391483542591f9b" 8673 +yoho-node-lib@=0.6.5:
  8674 + version "0.6.5"
  8675 + resolved "http://npm.yohops.com/yoho-node-lib/-/yoho-node-lib-0.6.5.tgz#ec9a4fefb03a1453316c085507595dbf2d50ebcc"
8707 dependencies: 8676 dependencies:
8708 dnscache "^1.0.1" 8677 dnscache "^1.0.1"
8709 handlebars "^4.0.5" 8678 handlebars "^4.0.5"
@@ -8711,9 +8680,9 @@ yoho-node-lib@=0.6.3: @@ -8711,9 +8680,9 @@ yoho-node-lib@=0.6.3:
8711 lodash "^4.13.1" 8680 lodash "^4.13.1"
8712 lru-cache "^4.1.1" 8681 lru-cache "^4.1.1"
8713 md5 "^2.1.0" 8682 md5 "^2.1.0"
8714 - memcached "^2.2.2"  
8715 moment "^2.13.0" 8683 moment "^2.13.0"
8716 pidusage "^1.1.6" 8684 pidusage "^1.1.6"
  8685 + redis "^2.8.0"
8717 request "^2.81.0" 8686 request "^2.81.0"
8718 uuid "^3.0.1" 8687 uuid "^3.0.1"
8719 walk "^2.3.9" 8688 walk "^2.3.9"