在 Redis Cluster 中使用 Lua 时,我应该指定完整的键名,还是可以只传递主题标签? [英] Should I specify full key names when using Lua in Redis Cluster, or can I just pass the hashtags?

查看:44
本文介绍了在 Redis Cluster 中使用 Lua 时,我应该指定完整的键名,还是可以只传递主题标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 Lua 脚本,我正在考虑迁移到 Redis 集群

I have Lua script which I'm considering migrating to Redis Cluster

调用eval时是否应该指定完整的键名?或者我可以通过指定主题标签来逃避吗?

Should I specify full key names when call eval? Or can I get away just by specifying hashtags?

例如,我希望只传递 {UNIQUE_HASH_TAG} 而不是 {UNIQUE_HASH_TAG}/key1, {UNIQUE_HASH_TAG}/key2 ... 等

For example, I wish to pass only {UNIQUE_HASH_TAG} instead of {UNIQUE_HASH_TAG}/key1, {UNIQUE_HASH_TAG}/key2 ... etc

我有很多键,而且逻辑非常复杂 - 有时我最终会动态生成键名,但是在相同哈希标签内.

I have lots of keys, and logic is pretty complicated - sometimes I end up generating key names dynamically but within the same hash tag.

只传递哈希标签而不是键名是否会违反某些规范?

Would I violate some specifications by passing just hash tags instead of key names?

推荐答案

我是否应该指定完整的键名

Should I specify full key names

这是推荐的做法.

我是否会违反某些规范

不,规范没有说明需要明确传递键名.KEYS/ARGV 机制是为集群准备的,但在集群实际出现之前.当时,散列标签不是集群设计的一部分,因此建议是避免在脚本中硬编码/动态生成键名,因为不能保证它们会在同一个集群散列中插槽.

No, the specs do not state that key names need to be explicitly passed. The KEYS/ARGV mechanism was put in place in preparation for the cluster but before the cluster actually came to be. At that time, hash tags were not a part of the cluster's design so the recommendation was to avoid hard-coding/dynamically generating key names in scripts as there's no assurance they'll be in the same cluster hash slot.

您的方法完全有效并且可以按预期工作.我想强调的是,这只有在您管理大量所谓的 {UNIQUE_HASH_TAG} 时才有意义 - 否则您只会遇到几个可能成为可扩展性挑战的插槽.

Your approach is perfectly valid and would work as expected. I do want to emphasize that this only makes sense if you're managing a lot of the so-called {UNIQUE_HASH_TAG}s - otherwise you'll be hitting just a few slots which could become a scalability challenge.

编辑:综上所述,您确实应该始终明确地将键名传递给脚本而不是欺骗.虽然这目前没有被阻止,但这种未指定的行为可能会在未来发生变化并导致您的代码损坏.

EDIT: All that said, you really should always explicitly pass the key names to the script rather than tricking. While this isn't currently blocked, this unspecified behavior may change in the future and result in breakage of your code.

这篇关于在 Redis Cluster 中使用 Lua 时,我应该指定完整的键名,还是可以只传递主题标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆