-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproducer-b.js
More file actions
46 lines (36 loc) · 1.02 KB
/
producer-b.js
File metadata and controls
46 lines (36 loc) · 1.02 KB
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
const { client, key } = require('./utils')
const date = new Date()
function main () {
let n = 0
const max = 100
async function produce () {
const c = client()
if (n > max) {
/**
* https://redis.io/commands/xlen
* Returns the number of entries inside a stream.
**/
const length = await c.xlenAsync(key)
// log informational stream growth statistics.
console.log(`${date.getTime()}: Stream "${key}" has ${length} messages.`)
process.exit()
}
/**
* https://redis.io/commands/xadd
* Appends the next message.
*
* Arguments:
* key - The name of our stream.
* '*' - Autogenerate id for the stream.
* 'n' - The name of the field entry.
* n - The value for the field entry.
* (Any number of field entry name/value pairs may be added.
**/
const id = await c.xaddAsync(key, '*', 'n', n)
console.log(`${date.getTime()}: Produced the number ${n} as message id ${id}`)
n += 1
produce()
}
produce()
}
main()