Redis 集群:hgetall 会在集群中的所有节点中搜索密钥吗?
Redis cluster: will hgetall search all nodes in cluster for key?
aws elasticache默认创建一个redis集群。
我正在使用 nodejs 并使用 ioredis。
我的问题是,如果我调用 hgetall,它会自动查询集群中的所有节点吗?
或者还有什么我需要做的吗?
更新:我觉得我这里说的不对,见。对于像 HGETALL
这样的命令,客户端库知道将它发送到哪里。
来自文档,强调我的:
Every command will be sent to exactly one node. For commands containing keys, (e.g. ... HGETALL), ioredis sends them to the node that [sic] serving the keys, and for other commands not containing keys, (e.g. INFO, KEYS and FLUSHDB), ioredis sends them to a random node.
不,不是自动的。您需要自己将 hgetall
发送到集群中的每个节点。有一个 nodes()
效用函数 returns 节点数组来促进这一点。
文档明确回答了这个问题并提供了示例,请参阅 https://github.com/luin/ioredis#running-commands-to-multiple-nodes。
您不需要查询所有节点。使用Redis.Cluster连接到集群,它会将命令发送到正确的节点。
Redis 集群的一个体面的客户端库应该实现 MOVED and ASK Redirection。客户端库的最终用户不必担心密钥的位置。
aws elasticache默认创建一个redis集群。
我正在使用 nodejs 并使用 ioredis。
我的问题是,如果我调用 hgetall,它会自动查询集群中的所有节点吗? 或者还有什么我需要做的吗?
更新:我觉得我这里说的不对,见HGETALL
这样的命令,客户端库知道将它发送到哪里。
来自文档,强调我的:
Every command will be sent to exactly one node. For commands containing keys, (e.g. ... HGETALL), ioredis sends them to the node that [sic] serving the keys, and for other commands not containing keys, (e.g. INFO, KEYS and FLUSHDB), ioredis sends them to a random node.
不,不是自动的。您需要自己将 hgetall
发送到集群中的每个节点。有一个 nodes()
效用函数 returns 节点数组来促进这一点。
文档明确回答了这个问题并提供了示例,请参阅 https://github.com/luin/ioredis#running-commands-to-multiple-nodes。
您不需要查询所有节点。使用Redis.Cluster连接到集群,它会将命令发送到正确的节点。
Redis 集群的一个体面的客户端库应该实现 MOVED and ASK Redirection。客户端库的最终用户不必担心密钥的位置。