简体   繁体   English

在启用集群模式的情况下批量上传到 Elasticache 时,redis-cli --pipe 会产生 MOVED 错误

[英]redis-cli --pipe yields MOVED errors when bulk uploading to Elasticache with cluster-mode enabled

I am trying to use redis-cli --pipe to bulk upload some commands to my AWS Elasticache for redis cluster.我正在尝试使用 redis-cli --pipe 将一些命令批量上传到我的 redis 集群的 AWS Elasticache。 The commands come from parsing a file via a custom awk command, which helps generate some HSET commands.这些命令来自通过自定义awk命令解析文件,这有助于生成一些HSET命令。 The awk command is in a custom shell script. awk命令位于自定义 shell 脚本中。 When my Elasticache for redis server had cluster-mode disabled, doing something like the following worked like a charm:当我的 redis 服务器的 Elasticache 禁用了集群模式时,执行类似以下的操作非常有效:

sh script_containing_awk.sh $FILE_TO_PARSE | redis-cli -h <Primary_endpoint> -p <port> --tls --cacert <path/to/cert> --pipe

Due to an internal project requirement, the Elasticache for Redis server has been re-created with cluster-mode enabled, and hence I am adding the -c flag to the above command to specify as such.由于内部项目要求,Redis 服务器的 Elasticache 已在启用集群模式的情况下重新创建,因此我在上述命令中添加-c标志以进行指定。

I see the following results when trying to work with my Elasticache for Redis server with cluster-mode enabled:在启用集群模式的情况下尝试使用 Redis 服务器的 Elasticache 时,我看到以下结果:

  • I can connect to the cluster via the configuration endpoint no problem!我可以通过配置端点连接到集群没问题!
  • Single command uploads work (ie: redis-cli -h <config_endpoint> -p <port> -c --tls --cacert <path/to/certs> SET key value )单个命令上传工作(即: redis-cli -h <config_endpoint> -p <port> -c --tls --cacert <path/to/certs> SET key value

It would be extremely convenient to just pipe output from my script to the cli:从我的脚本到 cli 只需 pipe output 将非常方便:

sh script_containing_awk.sh $FILE_TO_PARSE | redis-cli -h <config_endpoint> -p <port> -c --tls --cacert <path/to/cert> --pipe

but adding the --pipe flag results in "MOVED" errors.但添加--pipe标志会导致“MOVED”错误。

I have tried modifying the script to include {} (ex: HSET {user1}:hash field1 val1 field2 val2... brackets to try to force keys to the same CLUSTER SLOTS, but I still get the "MOVED" errors and I am attempting to bulk upload millions of keys so I don't think they would all fit in the same slot anyway.我尝试修改脚本以包含{} (例如: HSET {user1}:hash field1 val1 field2 val2...括号以尝试将键强制到相同的 CLUSTER SLOTS,但我仍然收到“MOVED”错误,我试图批量上传数百万个密钥,所以我认为它们无论如何都不会放在同一个插槽中。

Does anyone have experience getting --pipe to work with cluster-mode enabled Redis/Elasticache?有没有人有让--pipe与启用集群模式的 Redis/Elasticache 一起工作的经验?

Thanks!谢谢!

I am sure you understand that the core difference between Cluster Mode Disabled and Cluster Mode Enabled is that there is a split in your total Key slots.我相信您了解禁用集群模式和启用集群模式之间的核心区别在于您的总密钥槽存在差异。

Just to put in context;只是放在上下文中; CMD - Let's say we have 4 node cluster with 1 Primary and 3 Replicas. CMD - 假设我们有 4 个节点集群,其中 1 个主节点和 3 个副本节点。 if we have 100 key slots - All the 100 key slots will be there in all the nodes.如果我们有 100 个键槽 - 所有 100 个键槽都将存在于所有节点中。 3 of them will serve Read only commands and 1 of the node will serve all the commands.其中 3 个将提供只读命令,节点中的 1 个将提供所有命令。

CME - Let's say we have 4 nodes split in 2 shards - 1 replica and 1 primary each. CME - 假设我们有 4 个节点分成 2 个分片 - 每个节点 1 个副本和 1 个主节点。 We can look at them as logical sub-clusters ie.我们可以将它们视为逻辑子集群,即。 they will have different sets of key-slots.他们将有不同的键槽集。 Ideally a 50-50 split.理想的分配比例为 50-50。

Now, the MOVED message is not necessarily an error.现在,MOVED 消息不一定是错误。 When you connect to the configuration endpoint, by default you are being connected with one of the primary nodes (chosen at random, at first).当您连接到配置端点时,默认情况下您将连接到其中一个主要节点(首先随机选择)。 when you make a command, the client sends that command and the primary node decides if it has the correct hash-slot to serve that command.当您发出命令时,客户端发送该命令,主节点决定它是否具有正确的哈希槽来为该命令提供服务。

As explainedhere , if the node does not have the hash-slot that your client is looking for, it will redirect you with a MOVED message.如此所述,如果节点没有您的客户端正在寻找的哈希槽,它将使用 MOVED 消息重定向您。

So, I would assume MOVED messages are somewhat expected with CME clusters.因此,我假设 MOVED 消息在某种程度上与 CME 集群有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM