Authored by 李奇

redis transition

@@ -42,12 +42,31 @@ module.exports = { @@ -42,12 +42,31 @@ module.exports = {
42 }, 42 },
43 useOneapm: false, 43 useOneapm: false,
44 useCache: true, 44 useCache: true,
45 - memcache: {  
46 - master: ['127.0.0.1:11211'],  
47 - slave: ['127.0.0.1:11211'],  
48 - session: ['127.0.0.1:11211'],  
49 - timeout: 1000,  
50 - retries: 0 45 + redis: {
  46 + connect: {
  47 + host: '127.0.0.1',
  48 +
  49 + // host: '192.168.102.49',
  50 + port: '6379',
  51 + retry_strategy(options) {
  52 + if (options.error && options.error.code === 'ECONNREFUSED') {
  53 + console.log('redis连接不成功');
  54 + }
  55 + if (options.total_retry_time > 1000 * 60 * 60 * 6) {
  56 + console.log('redis连接超时');
  57 + return;
  58 + }
  59 + if (options.attempt > 10) {
  60 + return 1000 * 60 * 60 * 0.5;
  61 + }
  62 + return Math.min(options.attempt * 100, 1000);
  63 + }
  64 + },
  65 + session: {
  66 + host: '127.0.01',
  67 + port: '6379',
  68 + prefix: 'yohoblk_session:'
  69 + }
51 }, 70 },
52 interfaceShunt: { 71 interfaceShunt: {
53 useInterfaceShunt: false, 72 useInterfaceShunt: false,
@@ -97,12 +116,30 @@ if (isProduction) { @@ -97,12 +116,30 @@ if (isProduction) {
97 service: 'http://api.yoho.yohoops.org/', 116 service: 'http://api.yoho.yohoops.org/',
98 singleApi: 'http://api.yoho.yohoops.org/', 117 singleApi: 'http://api.yoho.yohoops.org/',
99 }, 118 },
100 - memcache: {  
101 - master: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'],  
102 - slave: [],  
103 - session: ['memcache1.yohoops.org:12111', 'memcache2.yohoops.org:12111', 'memcache3.yohoops.org:12111'],  
104 - timeout: 100,  
105 - retries: 0 119 + redis: {
  120 + connect: {
  121 + host: 'web.redis.yohoops.org',
  122 + port: '6379',
  123 + retry_strategy(options) {
  124 + if (options.error && options.error.code === 'ECONNREFUSED') {
  125 + console.log('redis连接不成功');
  126 + }
  127 + if (options.total_retry_time > 1000 * 60 * 60 * 6) {
  128 + console.log('redis连接超时');
  129 + return;
  130 + }
  131 + if (options.attempt > 10) {
  132 + return 1000 * 60 * 60 * 0.5;
  133 + }
  134 + return Math.min(options.attempt * 100, 1000);
  135 + }
  136 + },
  137 + session: {
  138 + host: 'redis.web.yohoops.org',
  139 + port: '6379',
  140 + pass: 'redis9646',
  141 + prefix: 'yohoblk_session:'
  142 + }
106 }, 143 },
107 useOneapm: true, 144 useOneapm: true,
108 useCache: true, 145 useCache: true,
@@ -153,13 +190,6 @@ if (isProduction) { @@ -153,13 +190,6 @@ if (isProduction) {
153 service: process.env.TEST_SERVICE || 'http://service-test1.yohops.com:9999/', 190 service: process.env.TEST_SERVICE || 'http://service-test1.yohops.com:9999/',
154 singleApi: process.env.TEST_SINGLE || 'http://api-test1.yohops.com:9999/' 191 singleApi: process.env.TEST_SINGLE || 'http://api-test1.yohops.com:9999/'
155 }, 192 },
156 - memcache: {  
157 - master: ['127.0.0.1:11211'],  
158 - slave: ['127.0.0.1:11211'],  
159 - session: ['127.0.0.1:11211'],  
160 - timeout: 100,  
161 - retries: 0  
162 - },  
163 useOneapm: true, 193 useOneapm: true,
164 useCache: true 194 useCache: true
165 }); 195 });
@@ -20,14 +20,14 @@ const cookieParser = require('cookie-parser'); @@ -20,14 +20,14 @@ const cookieParser = require('cookie-parser');
20 const favicon = require('serve-favicon'); 20 const favicon = require('serve-favicon');
21 const yohoLib = require('yoho-node-lib'); 21 const yohoLib = require('yoho-node-lib');
22 const session = require('express-session'); 22 const session = require('express-session');
23 -const memcached = require('connect-memcached'); 23 +const redis = require('connect-redis');
24 const pkg = require('./package.json'); 24 const pkg = require('./package.json');
25 const devtools = require('./doraemon/middleware/devtools'); 25 const devtools = require('./doraemon/middleware/devtools');
26 const _ = require('lodash'); 26 const _ = require('lodash');
27 27
28 const uuid = require('uuid'); 28 const uuid = require('uuid');
29 29
30 -const MemcachedStore = memcached(session); 30 +const redisStore = redis(session);
31 31
32 // 全局注册library 32 // 全局注册library
33 yohoLib.global(config); 33 yohoLib.global(config);
@@ -79,10 +79,7 @@ exports.createApp = async (app) => { @@ -79,10 +79,7 @@ exports.createApp = async (app) => {
79 domain: 'yohoblk.com', 79 domain: 'yohoblk.com',
80 httpOnly: false 80 httpOnly: false
81 }, 81 },
82 - store: new MemcachedStore({  
83 - hosts: config.memcache.session,  
84 - prefix: 'yohoblk_session:'  
85 - }) 82 + store: new redisStore(config.redis.session)
86 })); 83 }));
87 84
88 app.use((req, res, next) => { 85 app.use((req, res, next) => {
@@ -30,8 +30,8 @@ @@ -30,8 +30,8 @@
30 "babel-polyfill": "^6.26.0", 30 "babel-polyfill": "^6.26.0",
31 "bluebird": "^3.4.2", 31 "bluebird": "^3.4.2",
32 "body-parser": "^1.15.2", 32 "body-parser": "^1.15.2",
33 - "connect-memcached": "^0.2.0",  
34 "connect-multiparty": "^2.0.0", 33 "connect-multiparty": "^2.0.0",
  34 + "connect-redis": "^3.3.3",
35 "cookie-parser": "^1.4.3", 35 "cookie-parser": "^1.4.3",
36 "express": "^4.15.4", 36 "express": "^4.15.4",
37 "express-session": "^1.14.1", 37 "express-session": "^1.14.1",
@@ -42,7 +42,6 @@ @@ -42,7 +42,6 @@
42 "lodash": "^4.15.0", 42 "lodash": "^4.15.0",
43 "lodash-cli": "^4.17.4", 43 "lodash-cli": "^4.17.4",
44 "lru-cache": "^4.1.1", 44 "lru-cache": "^4.1.1",
45 - "memcached": "^2.2.1",  
46 "mint-ui": "^1.0.2", 45 "mint-ui": "^1.0.2",
47 "moment": "^2.14.1", 46 "moment": "^2.14.1",
48 "morgan": "^1.7.0", 47 "morgan": "^1.7.0",
@@ -68,7 +67,7 @@ @@ -68,7 +67,7 @@
68 "yoho-cookie": "1.2.0", 67 "yoho-cookie": "1.2.0",
69 "yoho-jquery": "^2.2.4", 68 "yoho-jquery": "^2.2.4",
70 "yoho-md5": "^2.0.0", 69 "yoho-md5": "^2.0.0",
71 - "yoho-node-lib": "=0.6.1", 70 + "yoho-node-lib": "=0.6.6",
72 "yoho-qs": "1.0.1", 71 "yoho-qs": "1.0.1",
73 "yoho-store": "^1.3.20" 72 "yoho-store": "^1.3.20"
74 }, 73 },
@@ -1916,12 +1916,6 @@ connect-history-api-fallback@^1.3.0: @@ -1916,12 +1916,6 @@ connect-history-api-fallback@^1.3.0:
1916 version "1.5.0" 1916 version "1.5.0"
1917 resolved "http://npm.yohops.com/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#b06873934bc5e344fef611a196a6faae0aee015a" 1917 resolved "http://npm.yohops.com/connect-history-api-fallback/-/connect-history-api-fallback-1.5.0.tgz#b06873934bc5e344fef611a196a6faae0aee015a"
1918 1918
1919 -connect-memcached@^0.2.0:  
1920 - version "0.2.0"  
1921 - resolved "http://npm.yohops.com/connect-memcached/-/connect-memcached-0.2.0.tgz#64907180324e117d9e8f299c994c0cb03d5020cf"  
1922 - dependencies:  
1923 - memcached "2.2.x"  
1924 -  
1925 connect-multiparty@^2.0.0: 1919 connect-multiparty@^2.0.0:
1926 version "2.1.0" 1920 version "2.1.0"
1927 resolved "http://npm.yohops.com/connect-multiparty/-/connect-multiparty-2.1.0.tgz#b562232ea638e13222d87e7b67be437f7ad89814" 1921 resolved "http://npm.yohops.com/connect-multiparty/-/connect-multiparty-2.1.0.tgz#b562232ea638e13222d87e7b67be437f7ad89814"
@@ -1931,9 +1925,12 @@ connect-multiparty@^2.0.0: @@ -1931,9 +1925,12 @@ connect-multiparty@^2.0.0:
1931 qs "~6.5.1" 1925 qs "~6.5.1"
1932 type-is "~1.6.15" 1926 type-is "~1.6.15"
1933 1927
1934 -connection-parse@0.0.x:  
1935 - version "0.0.7"  
1936 - resolved "http://npm.yohops.com/connection-parse/-/connection-parse-0.0.7.tgz#18e7318aab06a699267372b10c5226d25a1c9a69" 1928 +connect-redis@^3.3.3:
  1929 + version "3.3.3"
  1930 + resolved "http://npm.yohops.com/connect-redis/-/connect-redis-3.3.3.tgz#0fb8f370192f62da75ec7a9507807599fbe15b37"
  1931 + dependencies:
  1932 + debug "^3.1.0"
  1933 + redis "^2.1.0"
1937 1934
1938 console-browserify@^1.1.0: 1935 console-browserify@^1.1.0:
1939 version "1.1.0" 1936 version "1.1.0"
@@ -2594,6 +2591,10 @@ dot-prop@^4.1.0, dot-prop@^4.1.1: @@ -2594,6 +2591,10 @@ dot-prop@^4.1.0, dot-prop@^4.1.1:
2594 dependencies: 2591 dependencies:
2595 is-obj "^1.0.0" 2592 is-obj "^1.0.0"
2596 2593
  2594 +double-ended-queue@^2.1.0-0:
  2595 + version "2.1.0-0"
  2596 + resolved "http://npm.yohops.com/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz#103d3527fd31528f40188130c841efdd78264e5c"
  2597 +
2597 duplexer2@0.0.2, duplexer2@~0.0.2: 2598 duplexer2@0.0.2, duplexer2@~0.0.2:
2598 version "0.0.2" 2599 version "0.0.2"
2599 resolved "http://npm.yohops.com/duplexer2/-/duplexer2-0.0.2.tgz#c614dcf67e2fb14995a91711e5a617e8a60a31db" 2600 resolved "http://npm.yohops.com/duplexer2/-/duplexer2-0.0.2.tgz#c614dcf67e2fb14995a91711e5a617e8a60a31db"
@@ -3992,13 +3993,6 @@ hasha@^2.2.0: @@ -3992,13 +3993,6 @@ hasha@^2.2.0:
3992 is-stream "^1.0.1" 3993 is-stream "^1.0.1"
3993 pinkie-promise "^2.0.0" 3994 pinkie-promise "^2.0.0"
3994 3995
3995 -hashring@3.2.x:  
3996 - version "3.2.0"  
3997 - resolved "http://npm.yohops.com/hashring/-/hashring-3.2.0.tgz#fda4efde8aa22cdb97fb1d2a65e88401e1c144ce"  
3998 - dependencies:  
3999 - connection-parse "0.0.x"  
4000 - simple-lru-cache "0.0.x"  
4001 -  
4002 hawk@3.1.3, hawk@~3.1.3: 3996 hawk@3.1.3, hawk@~3.1.3:
4003 version "3.1.3" 3997 version "3.1.3"
4004 resolved "http://npm.yohops.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4" 3998 resolved "http://npm.yohops.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4"
@@ -4683,12 +4677,6 @@ isstream@0.1.x, isstream@~0.1.2: @@ -4683,12 +4677,6 @@ isstream@0.1.x, isstream@~0.1.2:
4683 version "0.1.2" 4677 version "0.1.2"
4684 resolved "http://npm.yohops.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" 4678 resolved "http://npm.yohops.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
4685 4679
4686 -jackpot@>=0.0.6:  
4687 - version "0.0.6"  
4688 - resolved "http://npm.yohops.com/jackpot/-/jackpot-0.0.6.tgz#3cff064285cbf66f4eab2593c90bce816a821849"  
4689 - dependencies:  
4690 - retry "0.6.0"  
4691 -  
4692 jpeg-js@0.0.4: 4680 jpeg-js@0.0.4:
4693 version "0.0.4" 4681 version "0.0.4"
4694 resolved "http://npm.yohops.com/jpeg-js/-/jpeg-js-0.0.4.tgz#06aaf47efec7af0b1924a59cd695a6d2b5ed870e" 4682 resolved "http://npm.yohops.com/jpeg-js/-/jpeg-js-0.0.4.tgz#06aaf47efec7af0b1924a59cd695a6d2b5ed870e"
@@ -5336,13 +5324,6 @@ mem@^1.1.0: @@ -5336,13 +5324,6 @@ mem@^1.1.0:
5336 dependencies: 5324 dependencies:
5337 mimic-fn "^1.0.0" 5325 mimic-fn "^1.0.0"
5338 5326
5339 -memcached@2.2.x, memcached@^2.2.1, memcached@^2.2.2:  
5340 - version "2.2.2"  
5341 - resolved "http://npm.yohops.com/memcached/-/memcached-2.2.2.tgz#68f86ccfd84bcf93cc25ed46d6d7fc0c7521c9d5"  
5342 - dependencies:  
5343 - hashring "3.2.x"  
5344 - jackpot ">=0.0.6"  
5345 -  
5346 memory-fs@^0.2.0: 5327 memory-fs@^0.2.0:
5347 version "0.2.0" 5328 version "0.2.0"
5348 resolved "http://npm.yohops.com/memory-fs/-/memory-fs-0.2.0.tgz#f2bb25368bc121e391c2520de92969caee0a0290" 5329 resolved "http://npm.yohops.com/memory-fs/-/memory-fs-0.2.0.tgz#f2bb25368bc121e391c2520de92969caee0a0290"
@@ -7475,10 +7456,26 @@ redent@^2.0.0: @@ -7475,10 +7456,26 @@ redent@^2.0.0:
7475 indent-string "^3.0.0" 7456 indent-string "^3.0.0"
7476 strip-indent "^2.0.0" 7457 strip-indent "^2.0.0"
7477 7458
  7459 +redis-commands@^1.2.0:
  7460 + version "1.3.5"
  7461 + resolved "http://npm.yohops.com/redis-commands/-/redis-commands-1.3.5.tgz#4495889414f1e886261180b1442e7295602d83a2"
  7462 +
7478 redis-commands@^1.3.1: 7463 redis-commands@^1.3.1:
7479 version "1.3.4" 7464 version "1.3.4"
7480 resolved "http://npm.yohops.com/redis-commands/-/redis-commands-1.3.4.tgz#4822139fab8eaf366fdaaa98a12736054a2fd625" 7465 resolved "http://npm.yohops.com/redis-commands/-/redis-commands-1.3.4.tgz#4822139fab8eaf366fdaaa98a12736054a2fd625"
7481 7466
  7467 +redis-parser@^2.6.0:
  7468 + version "2.6.0"
  7469 + resolved "http://npm.yohops.com/redis-parser/-/redis-parser-2.6.0.tgz#52ed09dacac108f1a631c07e9b69941e7a19504b"
  7470 +
  7471 +redis@^2.1.0, redis@^2.8.0:
  7472 + version "2.8.0"
  7473 + resolved "http://npm.yohops.com/redis/-/redis-2.8.0.tgz#202288e3f58c49f6079d97af7a10e1303ae14b02"
  7474 + dependencies:
  7475 + double-ended-queue "^2.1.0-0"
  7476 + redis-commands "^1.2.0"
  7477 + redis-parser "^2.6.0"
  7478 +
7482 reduce-css-calc@^1.2.6: 7479 reduce-css-calc@^1.2.6:
7483 version "1.3.0" 7480 version "1.3.0"
7484 resolved "http://npm.yohops.com/reduce-css-calc/-/reduce-css-calc-1.3.0.tgz#747c914e049614a4c9cfbba629871ad1d2927716" 7481 resolved "http://npm.yohops.com/reduce-css-calc/-/reduce-css-calc-1.3.0.tgz#747c914e049614a4c9cfbba629871ad1d2927716"
@@ -7816,10 +7813,6 @@ ret@~0.1.10: @@ -7816,10 +7813,6 @@ ret@~0.1.10:
7816 version "0.1.15" 7813 version "0.1.15"
7817 resolved "http://npm.yohops.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc" 7814 resolved "http://npm.yohops.com/ret/-/ret-0.1.15.tgz#b8a4825d5bdb1fc3f6f53c2bc33f81388681c7bc"
7818 7815
7819 -retry@0.6.0:  
7820 - version "0.6.0"  
7821 - resolved "http://npm.yohops.com/retry/-/retry-0.6.0.tgz#1c010713279a6fd1e8def28af0c3ff1871caa537"  
7822 -  
7823 rgb@~0.1.0: 7816 rgb@~0.1.0:
7824 version "0.1.0" 7817 version "0.1.0"
7825 resolved "http://npm.yohops.com/rgb/-/rgb-0.1.0.tgz#be27b291e8feffeac1bd99729721bfa40fc037b5" 7818 resolved "http://npm.yohops.com/rgb/-/rgb-0.1.0.tgz#be27b291e8feffeac1bd99729721bfa40fc037b5"
@@ -8158,10 +8151,6 @@ signal-exit@^3.0.0, signal-exit@^3.0.2: @@ -8158,10 +8151,6 @@ signal-exit@^3.0.0, signal-exit@^3.0.2:
8158 version "3.0.2" 8151 version "3.0.2"
8159 resolved "http://npm.yohops.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" 8152 resolved "http://npm.yohops.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
8160 8153
8161 -simple-lru-cache@0.0.x:  
8162 - version "0.0.2"  
8163 - resolved "http://npm.yohops.com/simple-lru-cache/-/simple-lru-cache-0.0.2.tgz#d59cc3a193c1a5d0320f84ee732f6e4713e511dd"  
8164 -  
8165 slash@^1.0.0: 8154 slash@^1.0.0:
8166 version "1.0.0" 8155 version "1.0.0"
8167 resolved "http://npm.yohops.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" 8156 resolved "http://npm.yohops.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55"
@@ -10031,9 +10020,9 @@ yoho-md5@^2.0.0: @@ -10031,9 +10020,9 @@ yoho-md5@^2.0.0:
10031 version "2.0.0" 10020 version "2.0.0"
10032 resolved "http://npm.yohops.com/yoho-md5/-/yoho-md5-2.0.0.tgz#e801a5cce8e08f5d7211e9a2e789ea7275eb9332" 10021 resolved "http://npm.yohops.com/yoho-md5/-/yoho-md5-2.0.0.tgz#e801a5cce8e08f5d7211e9a2e789ea7275eb9332"
10033 10022
10034 -yoho-node-lib@=0.6.1:  
10035 - version "0.6.1"  
10036 - resolved "http://npm.yohops.com/yoho-node-lib/-/yoho-node-lib-0.6.1.tgz#df5f4a22a945371b84db63360d44d37ff68510e6" 10023 +yoho-node-lib@=0.6.6:
  10024 + version "0.6.6"
  10025 + resolved "http://npm.yohops.com/yoho-node-lib/-/yoho-node-lib-0.6.6.tgz#2c727bed970d8829730ac077bd379aa506db16f3"
10037 dependencies: 10026 dependencies:
10038 dnscache "^1.0.1" 10027 dnscache "^1.0.1"
10039 handlebars "^4.0.5" 10028 handlebars "^4.0.5"
@@ -10041,9 +10030,9 @@ yoho-node-lib@=0.6.1: @@ -10041,9 +10030,9 @@ yoho-node-lib@=0.6.1:
10041 lodash "^4.13.1" 10030 lodash "^4.13.1"
10042 lru-cache "^4.1.1" 10031 lru-cache "^4.1.1"
10043 md5 "^2.1.0" 10032 md5 "^2.1.0"
10044 - memcached "^2.2.2"  
10045 moment "^2.13.0" 10033 moment "^2.13.0"
10046 pidusage "^1.1.6" 10034 pidusage "^1.1.6"
  10035 + redis "^2.8.0"
10047 request "^2.81.0" 10036 request "^2.81.0"
10048 uuid "^3.0.1" 10037 uuid "^3.0.1"
10049 walk "^2.3.9" 10038 walk "^2.3.9"