EVAL "return redis.call('GET', KEYS[1])" 1 user:42
So Redis, especially Redis Cluster, knows which keys the script accesses and can route it and check they are in one slot
Declared keys tell Redis which keys a script touches. This has two benefits in Redis Cluster:
• A cluster-aware client can send the script to the node that owns the keys' slot.
• Redis can reject a script that accesses keys in different slots.
Building key names inside the script may work on a single instance. But it breaks under Cluster and goes against the documented rules. It is not true that "Building key names inside a script is a syntax error": Redis cannot see the problem at all, which is the danger.
Read more