如果 Elasticache 决定在我的脚本 运行 时重新分片,会发生什么情况?
What happens if Elasticache decides to reshard while my script is running?
我有一些涉及少数几个键的脚本。如果 Elasticache 决定在我的脚本 运行 时重新分片,会发生什么情况?它会在移动底层键之前等待我的脚本完成吗?还是我应该假设情况并非如此,并在设计我的应用程序时考虑到这种极端情况?
一个示例是一次递增 2 个键的脚本。我可能会收到一个 "cluster error",这意味着出了点问题,我必须再次执行我的脚本(并可能最终导致一个键被递增两次,另一个被递增一次)
假设您正在谈论一个 Lua 脚本,只要您在参数中传递键(而不是在脚本中硬编码),您应该是好的。这将是全有或全无。如果您没有使用 Lua 脚本 - 考虑这样做
来自EVAL command:
All Redis commands must be analyzed before execution to determine
which keys the command will operate on. In order for this to be true
for EVAL, keys must be passed explicitly. This is useful in many ways,
but especially to make sure Redis Cluster can forward your request to
the appropriate cluster node.
来自 AWS ElastiCache - Best Practices: Online Cluster Resizing:
During resharding, we recommend the following:
Avoid expensive commands – Avoid running any computationally and I/O
intensive operations, such as the KEYS and SMEMBERS commands. We
suggest this approach because these operations increase the load on
the cluster and have an impact on the performance of the cluster.
Instead, use the SCAN and SSCAN commands.
Follow Lua best practices – Avoid long running Lua scripts, and always
declare keys used in Lua scripts up front. We recommend this approach
to determine that the Lua script is not using cross slot commands.
Ensure that the keys used in Lua scripts belong to the same slot.
我有一些涉及少数几个键的脚本。如果 Elasticache 决定在我的脚本 运行 时重新分片,会发生什么情况?它会在移动底层键之前等待我的脚本完成吗?还是我应该假设情况并非如此,并在设计我的应用程序时考虑到这种极端情况?
一个示例是一次递增 2 个键的脚本。我可能会收到一个 "cluster error",这意味着出了点问题,我必须再次执行我的脚本(并可能最终导致一个键被递增两次,另一个被递增一次)
假设您正在谈论一个 Lua 脚本,只要您在参数中传递键(而不是在脚本中硬编码),您应该是好的。这将是全有或全无。如果您没有使用 Lua 脚本 - 考虑这样做
来自EVAL command:
All Redis commands must be analyzed before execution to determine which keys the command will operate on. In order for this to be true for EVAL, keys must be passed explicitly. This is useful in many ways, but especially to make sure Redis Cluster can forward your request to the appropriate cluster node.
来自 AWS ElastiCache - Best Practices: Online Cluster Resizing:
During resharding, we recommend the following:
Avoid expensive commands – Avoid running any computationally and I/O intensive operations, such as the KEYS and SMEMBERS commands. We suggest this approach because these operations increase the load on the cluster and have an impact on the performance of the cluster. Instead, use the SCAN and SSCAN commands.
Follow Lua best practices – Avoid long running Lua scripts, and always declare keys used in Lua scripts up front. We recommend this approach to determine that the Lua script is not using cross slot commands. Ensure that the keys used in Lua scripts belong to the same slot.