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?
问题:
回答1:
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.