Configure BullMQ to work with Redis Cluster using hash tags
Bull internals require atomic operations that span different keys. This behavior breaks Redis’s rules for cluster configurations. However, it is still possible to use a cluster environment by using the proper bull prefix option as a cluster “hash tag”.
Hash tags are used to guarantee that certain keys are placed in the same hash slot. A hash tag is defined with brackets. A key that has a substring inside brackets will use that substring to determine in which hash slot the key will be placed.Read more about hash tags in the Redis cluster tutorial.
If you use several queues in the same cluster, you should use different prefixes so that the queues are evenly placed in the cluster nodes, potentially increasing performance and memory usage.
// Good: Different prefixes for load distributionconst emailQueue = new Queue('emails', { prefix: '{emails}' });const videoQueue = new Queue('videos', { prefix: '{videos}' });const imageQueue = new Queue('images', { prefix: '{images}' });// Bad: Same prefix causes all queues to be on same nodeconst emailQueue = new Queue('emails', { prefix: '{myapp}' });const videoQueue = new Queue('videos', { prefix: '{myapp}' });const imageQueue = new Queue('images', { prefix: '{myapp}' });