使用nodejs拆分读写到redis

Splitting read & write to redis with nodejs

我在三个单独的实例上设置了 redis,并以 1 个实例是主实例,2 个是主实例的副本的方式配置了它们。我使用哨兵来确保设置的高可用性。我有一个需要使用 redis 的 nodejs 应用程序。我如何在我的应用程序中实现读写分离,因为万一我的 Redis 主服务器出现故障,我的一个只读副本成为主服务器并且需要写入它。

据我所知,ioredis 是唯一支持哨兵的 node redis 客户端。

"ioredis guarantees that the node you connected to is always a master even after a failover. When a failover happens, instead of trying to reconnect to the failed node (which will be demoted to slave when it's available again), ioredis will ask sentinels for the new master node and connect to it. All commands sent during the failover are queued and will be executed when the new connection is established so that none of the commands will be lost."