Connection to Redis cluster failed

本小妞迷上赌 提交于 2019-12-04 15:43:29

Ok, I think there is a confusion here.

A Redis Cluster deployment is not the same than a number of standard Redis instances protected by Sentinel. Two very different things.

The click-to-deploy option of GCE deploys a number of standard Redis instances protected by Sentinel, not Redis Cluster.

ioredis can handle both kind of deployments, but you have to use the corresponding API. Here, you were trying to use the Redis Cluster API, resulting in this error (cluster related commands are not activated for standard Redis instances).

According to ioredis documentation, you are supposed to connect with:

var redis = new Redis({
    sentinels: [{ host: hostMaster, port: 26379 },
                { host: hostSlab1, port: 26379 },
                { host: hostSlab2, port: 26379 } ],
    name: 'mymaster'
});

Of course, check the sentinel ports and name of the master. ioredis will manage automatically the switch to a slave instance when the master fails, and sentinel will ensure the slave is promoted as master just before.

Note that since you use pub/sub, you will need several redis connections.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!