I am using Redis in an Express application. My app is both a publisher and consumer of streams, using a single redis connection (redis.createClient). I have a question on the best way to manage a perpetual subscription (with xreadgroup). Currently I am doing this:
const readStream = () => xreadgroup('GROUP' appId, consumerId, 'BLOCK', 1, 'COUNT', 1, 'STREAMS' key, '>')
.then(handleData)
.then(() => setImmeadiate(readStream));
Where xreadgroup
is just a promisified version of node-redis' xreadgroup
.
My question - What is the appropriate usage of BLOCK? If I block indefinitely or for a long period, then my client cannot publish any messages (with xadd
) until it is unblocked, or the block times out. Since I must use some sort of loop/recursion in order to keep reading events, BLOCK
appears to be fairly unnecessary; can I just leave it off and is this the expected usage?
Likewise, is using setImmeadiate appropriate or would process.nextTick or an async loop be preferred?
There is very little documentation in node-redis and the few examples simply read the messages once after blocking and do not produce/consume on the same client.