Full key names should be specified when using Lua in a Redis group

I have a Lua script that I plan to migrate to a Redis cluster

Should I provide full key names when calling http://redis.io/commands/eval ? Or can I leave just by specifying the hashtags?

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

I have many keys, and the logic is quite complicated - sometimes I end up generating key names dynamically, but inside the same hash tag.

Would I break some specifications by passing only hash tags instead of key names?

+7
lua redis
source share
1 answer

Should I include full key names

This is a recommended practice.

I would violate some specifications

No, the specifications do not indicate that key names should be explicitly passed. The KEYS / ARGV engine was put in place to prepare for the cluster, but before the cluster actually became. Hash tags were not part of the cluster structure at the time, so the recommendation was to avoid hard coding / dynamic generation of key names in scripts, since there is no certainty that they will be in the same cluster hash slot.

Your approach is absolutely correct and will work as expected. I want to emphasize that this makes sense only if you control a large number of so-called {UNIQUE_HASH_TAG} s, otherwise you will only beat a few slots, which can become a scalability problem.

EDIT . That being said, you really should always explicitly pass the key names to the script, and not cheat. Until it is locked, this unspecified behavior may change in the future and cause your code to crash.

+3
source share

All Articles