Authored by 郝肖肖

'按规定存入json字符串'

@@ -25,11 +25,21 @@ const getter = (client, path, memory, cache) => { @@ -25,11 +25,21 @@ const getter = (client, path, memory, cache) => {
25 25
26 let keys = path.replace(/^\/(pc|wap)\//, '').split('/'); 26 let keys = path.replace(/^\/(pc|wap)\//, '').split('/');
27 27
28 - memory && _.set(memory, keys, data.toString('utf8') === 'true' ? true : false); 28 + if (keys.indexOf('json') > -1) { // /pc|wap/json/... is JSON string
  29 + try {
  30 + memory && _.set(memory, keys, JSON.parse(data.toString('utf8')));
  31 + } catch (e) {
  32 + console.log('%s catch: %s', e.message, path, data.toString('utf8'));
  33 + }
  34 + } else {
  35 + memory && _.set(memory, keys, data.toString('utf8') === 'true' ? true : false);
  36 + }
  37 +
29 if (cache) { 38 if (cache) {
30 cache.set('zookeeper:' + path, data.toString('utf8'), ONE_MONTH).catch(console.error); 39 cache.set('zookeeper:' + path, data.toString('utf8'), ONE_MONTH).catch(console.error);
31 console.log('cache %s data: %s', 'zookeeper:' + path, data.toString('utf8')); 40 console.log('cache %s data: %s', 'zookeeper:' + path, data.toString('utf8'));
32 } 41 }
  42 +
33 console.log('%s data: %s', path, data.toString('utf8')); 43 console.log('%s data: %s', path, data.toString('utf8'));
34 } 44 }
35 ) 45 )
1 { 1 {
2 "name": "yoho-zookeeper", 2 "name": "yoho-zookeeper",
3 - "version": "1.0.8", 3 + "version": "1.0.9",
4 "description": "", 4 "description": "",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {