UNPKG

527 BJavaScriptView Raw
1const _ = require('lodash');
2
3module.exports = exports = {};
4
5exports.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};