Why there are KEYS and ARGV arrays when calling Re

2020-05-30 03:28发布

When calling Lua scripts from within Redis, it is possible to pass values in two arrays: KEYS and ARGV. What is the difference? How does Redis treat values in the KEYS array? What if, in my script, I have to use keys dynamically generated at run time?

标签: redis
1条回答
smile是对你的礼貌
2楼-- · 2020-05-30 04:15

All your questions are answered at the EVAL page, but since you asked...:

What is the difference?

KEYS is used to pass key names whereas ARGS should be for anything else. This isn't exactly enforced (i.e. most times you'd be ok mixing them) but could lead to potential problems if not followed.

How does Redis treat values in the KEYS array?

The contents of KEYS are checked to verify that all keys are available to the Redis shard that's running the script. This mechanism is in place to allow running scripts in a Redis cluster deployment.

What if, in my script, I have to use keys dynamically generated at run time?

See previous answers - that's doable but you'd going against the recommendations. Your script will be safe to run only on a stand alone Redis instance and since this behavior isn't specified, it may break in future releases.

查看更多
登录 后发表回答