使用 Redis Cluster,是否可以将散列标签传递给 eval?

With Redis Cluster, is to possible to just pass the hash tags to eval?

来自 Redis documentation on eval 它说:

should not represent key names

Redis cluster tutorial

Hash tags are documented in the Redis Cluster specification, but the gist is that if there is a substring between {} brackets in a key, only what is inside the string is hashed, so for example this{foo}key and another{foo}key are guaranteed to be in the same hash slot, and can be used together in a command with multiple keys as arguments.

是否可以只传递散列标签或者只传递一个带有该散列标签的键?我们希望 eval 的内容与由另一个键的内容确定的一组动态键一起工作,但每个键都属于同一个哈希标签。

是的,应该有效。

the documentation所述:

All Redis commands must be analyzed before execution to determine which keys the command will operate on.... Note this rule is not enforced in order to provide the user with opportunities to abuse the Redis single instance configuration, at the cost of writing scripts not compatible with Redis Cluster.

所以不遵守这个规则也没关系,只要你保证你的脚本兼容Redis Cluster。这意味着对 EVAL 的调用应该指定一组散列到一个且仅一个服务器的密钥。

只需使用一个键(例如 {foo})就可以正常工作。