Redis Lua 里 KEYS 和 ARGV 区别

While key names in Redis are just strings, unlike any other string values, these represent keys in the database. The name of a key is a fundamental concept in Redis and is the basis for operating the Redis Cluster.

Important: to ensure the correct execution of scripts, both in standalone and clustered deployments, all names of keys that a script accesses must be explicitly provided as input key arguments. The script should only access keys whose names are given as input arguments. Scripts should never access keys with programmatically-generated names or based on the contents of data structures stored in the database.(重要提示: 为了确保在独立部署和集群部署中正确执行脚本,必须显式提供脚本访问的所有键的名称作为输入键参数。脚本应该只访问名称作为输入参数的键。脚本不应访问具有编程生成的名称的密钥或基于存储在数据库中的数据结构的内容的密钥。)

redis> EVAL "return { KEYS[1], KEYS[2], ARGV[1], ARGV[2], ARGV[3] }" 2 key1 key2 arg1 arg2 arg3
1) "key1"
2) "key2"
3) "arg1"
4) "arg2"
5) "arg3"