1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = parseKeyspaceEvents;
|
7 | exports.emitNotification = emitNotification;
|
8 | var allEventsDisabled = {
|
9 | g: false,
|
10 | string: false,
|
11 | l: false,
|
12 | s: false,
|
13 | h: false,
|
14 | z: false,
|
15 | x: false,
|
16 | e: false
|
17 | };
|
18 |
|
19 | function parseEvents(keyspaceEventsConfigString) {
|
20 | var result = Object.assign({}, allEventsDisabled);
|
21 | var allEvents = 'g$lshzxe';
|
22 | var unAliasedString = keyspaceEventsConfigString.replace('A', allEvents);
|
23 | result.g = unAliasedString.includes('g');
|
24 | result.string = unAliasedString.includes('$');
|
25 | result.l = unAliasedString.includes('l');
|
26 | result.s = unAliasedString.includes('s');
|
27 | result.h = unAliasedString.includes('h');
|
28 | result.z = unAliasedString.includes('z');
|
29 | result.x = unAliasedString.includes('x');
|
30 | result.e = unAliasedString.includes('e');
|
31 | return result;
|
32 | }
|
33 |
|
34 | function parseKeyspaceEvents(keyspaceEventsConfigString) {
|
35 | var keyspaceConfig = {
|
36 | K: Object.assign({}, allEventsDisabled),
|
37 | E: Object.assign({}, allEventsDisabled)
|
38 | };
|
39 | var isKeyspace = keyspaceEventsConfigString.includes('K');
|
40 | var isKeyevent = keyspaceEventsConfigString.includes('E');
|
41 | if (isKeyspace) {
|
42 | keyspaceConfig.K = parseEvents(keyspaceEventsConfigString);
|
43 | }
|
44 | if (isKeyevent) {
|
45 | keyspaceConfig.E = parseEvents(keyspaceEventsConfigString);
|
46 | }
|
47 | return keyspaceConfig;
|
48 | }
|
49 |
|
50 | function createChannelString(type, name) {
|
51 | var database = 0;
|
52 | var typeString = type === 'K' ? 'keyspace' : 'keyevent';
|
53 | var channel = '__' + typeString + '@' + database + '__:' + name;
|
54 | return channel;
|
55 | }
|
56 |
|
57 | function emitNotification(redisMock, notifType, key, event) {
|
58 | if (redisMock.keyspaceEvents.K[notifType] === true) {
|
59 | redisMock.publish(createChannelString('K', key), event);
|
60 | }
|
61 | if (redisMock.keyspaceEvents.E[notifType] === true) {
|
62 | redisMock.publish(createChannelString('E', event), key);
|
63 | }
|
64 | } |
\ | No newline at end of file |