forked from hearit-io/redis-channels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
constants.js
186 lines (165 loc) · 4.33 KB
/
constants.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// ============================================================================|
/*
* Project : HEARIT
*
* Developing an innovative connected/smart home intelligent
* management system for the needs of blind or visually impaired
* persons.
*
* The project has received funding from the European Regional
* Development Fund through the Operational Program
* "Innovation and Competitiveness"
*
* Purpose:
* Defines all used constants in the package.
*
* Author: hearit.io
*
* License:
*
* MIT License
*
*/
// ============================================================================|
'use strict'
// ----------------------------------------------------------------------------|
// Common definitions
// ----------------------------------------------------------------------------|
// Separators used to compose Redis keys and indexes.
const sep = {
HASH: '#',
STREAM: '|',
INDEX: ':',
OPEN: '[',
CLOSE: ']',
BIND: '-'
}
Object.freeze(sep)
// ----------------------------------------------------------------------------|
// The application is prepared for using a Redis cluster, it uses a fixed
// pre-sharded approach.
//
// All the stream keys are fix sharded by including a hash tags in
// the key. We split the hash slots (16384) in 32 or 64 shards in order to
// implement load balancing in a cluster environment.
//
// The stream keys are going to be dynamically evenly distributed
// during creation time. A look-up hash and sorted set will be used to
// update the mapping.
// ----------------------------------------------------------------------------|
const shards32 = [
'{10}', '{113}', '{21}', '{3}',
'{61}', '{72}', '{50}', '{43}',
'{11}', '{112}', '{20}', '{2}',
'{60}', '{73}', '{51}', '{42}',
'{12}', '{111}', '{23}', '{1}',
'{63}', '{70}', '{52}', '{41}',
'{13}', '{110}', '{22}', '{0}',
'{62}', '{71}', '{53}', '{40}'
]
const shards64 = [
'{10}', '{18}', '{113}', '{342}', '{29}', '{21}',
'{3}', '{122}', '{69}', '{61}', '{72}', '{162}',
'{50}', '{58}', '{153}', '{43}', '{11}', '{19}',
'{112}', '{343}', '{28}', '{20}', '{2}', '{123}',
'{68}', '{60}', '{73}', '{163}', '{51}', '{59}',
'{152}', '{42}', '{12}', '{102}', '{111}', '{119}',
'{133}', '{23}', '{1}', '{9}', '{173}', '{63}',
'{70}', '{78}', '{52}', '{142}', '{49}', '{41}',
'{13}', '{103}', '{110}', '{118}', '{132}', '{22}',
'{0}', '{8}', '{172}', '{62}', '{71}', '{79}',
'{53}', '{143}', '{48}', '{40}'
]
const shards = {
32: shards32,
64: shards64
}
Object.freeze(shards)
const origin = {
CONTEXT: 'context',
CONTENT: 'content'
}
Object.freeze(origin)
const context = {
UNSUBSCRIBE: 'unsubscribe',
ORIGIN: 'origin'
}
Object.freeze(context)
// ----------------------------------------------------------------------------|
// Channel definitions
// ----------------------------------------------------------------------------|
// Property names used in the option properites.
//
const opt = {
// Channels options
CHANNELS: 'channels',
LOG: 'log',
OVERFLOW: 'overflow',
SCHEMA: 'schema',
SLOTS: 'slots',
VESRION: 'version',
APPLICATION: 'application',
SHARDED: 'sharded',
// Redis options
REDIS: 'redis',
NODES: 'nodes',
URL: 'url'
}
Object.freeze(opt)
const tun = {
TEAM: 'team',
CONNECTION: 'connection',
CONSUMER: 'consumer',
KEY: 'key'
}
Object.freeze(tun)
const msg = {
ID: 'id',
DATA: 'data'
}
Object.freeze(msg)
// ----------------------------------------------------------------------------|
// Key parts used in the pre-sharded mapping (hash and sorted sets).
const pre = {
KEYS: 'keys',
SHARDS: 'shards'
}
Object.freeze(pre)
//
// The maximum number of elements in a stream before overflow (overwrite).
//
const overflowStreamElemNumber = 100
//
// Consumer block time out in milliseconds (used in XREADGROUP).
//
const blockStreamConsumerTimeOutMs = 10000
//
// The maximum number of elements to consume in one run (used in XREADGROUP).
//
const maxMessageStreamConsumePerRun = 100
//
// Defaults
//
const defaultAppName = 'app'
const defaultVersion = 1
const defaultSlotsNumb = 32
const defaultSchema = 'channels'
const defaultOriginType = 'all'
module.exports = {
sep,
opt,
pre,
tun,
msg,
origin,
shards,
context,
defaultSchema,
defaultAppName,
defaultVersion,
defaultSlotsNumb,
defaultOriginType,
overflowStreamElemNumber,
blockStreamConsumerTimeOutMs,
maxMessageStreamConsumePerRun
}