Showing
2 changed files
with
12 additions
and
2 deletions
@@ -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 | ) |
-
Please register or login to post a comment