You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// We write an event to the stream 'my awesome fastify stream name', setting 'key' to 'value'
143
+
awaitfastify.redis.xadd(['my awesome fastify stream name', '*', 'hello', 'fastify is awesome'])
144
+
145
+
// We read events from the beginning of the stream called 'my awesome fastify stream name'
146
+
let redisStream =awaitfastify.redis.xread(['STREAMS', 'my awesome fastify stream name', 0])
147
+
148
+
// We parse the results
149
+
let response = []
150
+
let events = redisStream[0][1]
151
+
152
+
for (let i =0; i <events.length; i++) {
153
+
conste= events[i]
154
+
response.push(`#LOG: id is ${e[0].toString()}`)
155
+
156
+
// We log each key
157
+
for (constkeyin e[1]) {
158
+
response.push(e[1][key].toString())
159
+
}
160
+
}
161
+
162
+
reply.status(200)
163
+
return { output: response }
164
+
// Will return something like this :
165
+
// { "output": ["#LOG: id is 1559985742035-0", "hello", "fastify is awesome"] }
166
+
})
167
+
168
+
fastify.listen(3000, function (err) {
169
+
if (err) {
170
+
fastify.log.error(err)
171
+
process.exit(1)
172
+
}
173
+
})
174
+
```
175
+
*NB: you will find more information about Redis streams and the relevant commands [here](https://redis.io/topics/streams-intro) and [here](https://redis.io/commands#stream).*
0 commit comments