Redis Cluster(3.x ~ 4.x) での Pub/Sub

揮発性のあるtopic(channel)に対してのPub/Subが欲しい案件が出てきたので、Redis ClusterでPub/Subでもしようかと思っていたのでちょっと調べてみた。そのメモ書き。

Redis pub/subの内部的な話し

このブログが参考になる。
https://making.pusher.com/redis-pubsub-under-the-hood/

Redis Cluster での Pub/Sub

現状のRedis clusterでのpub/subの仕様。

https://redis.io/topics/cluster-spec#publishsubscribe

In a Redis Cluster clients can subscribe to every node, and can also publish to every other node. The cluster will make sure that published messages are forwarded as needed. The current implementation will simply broadcast each published message to all other nodes, but at some point this will be optimized either using Bloom filters or other algorithms.

あかん。
これだと、Redis Clusterにnode足せば出すほど、networkがボトルネックになっていく。

issueにもあった。
https://github.com/antirez/redis/issues/2672

Bloom filterを使った最適化の予定があるみたいなので、それを待つことになりそう。

Redis 4.2のroadmapに、DisqueをRedis moduleとして作り直すとあるので、もしかしたらそれと関連して4.2でなんかしらの修正が入りそう。
https://gist.github.com/antirez/a3787d538eec3db381a41654e214b31d