1 | const _ = require('lodash');
|
2 |
|
3 | module.exports = exports = {};
|
4 |
|
5 | exports.parseRedisKeyStringToObject = function parseRedisKey(redis_key_string) {
|
6 | var matches = [];
|
7 |
|
8 | var redis_key_regx = /([^:]+):?([^:]*)/gi;
|
9 |
|
10 | var match = redis_key_regx.exec(redis_key_string);
|
11 | while (match != null) {
|
12 | matches.push(match);
|
13 | match = redis_key_regx.exec(redis_key_string);
|
14 | }
|
15 |
|
16 | return _.reduce(matches, (result, match) => {
|
17 |
|
18 | let key = match[1];
|
19 | let value = match[2];
|
20 | result[key] = value;
|
21 |
|
22 | return result;
|
23 | }, {});
|
24 | };
|