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

笑着哭i 提交于 2019-12-11 11:18:42

问题


From the Redis documentation on eval it says:

should not represent key names

In the 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.

Is it possible to just pass the hash tag or perhaps only one key with that hash tag? We would like the contents of eval to work with a dynamic set of keys determine by the contents of another key, but every key would be belong to the same hash tag.


回答1:


Yes, that should work.

As noted in 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.

So it's fine not to obey this rule, as long as you ensure that your scripts are compatible with Redis Cluster. That means that the call to EVAL should specify a set of keys that hash to one and only one server.

Just using a single key (e.g. {foo}) should work fine.



来源:https://stackoverflow.com/questions/49926357/with-redis-cluster-is-to-possible-to-just-pass-the-hash-tags-to-eval

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!