5

I want to run many Lua scripts one after another, without allowing any commands to run in between. I also need to pass the result of the first script to the second one, etc.

I've solved the problem temporarily by putting all my scripts in one file. However, the second script modifies a key returned by the first script. Because of this, putting everything in one file violates the EVAL command semantics as all the keys that the second script uses should be passed using the KEYS array.

kryo
  • 716
  • 1
  • 6
  • 24

2 Answers2

11

Actually, it is possible. Redis has an undocumented feature that allows doing just that. The basic premise is that once you EVAL or SCRIPT LOAD a script, you can call that script from another one by invoking the function f_<sha1 hash> (where sha1 hash is the SHA1 hash of the first script).

Credit for this goes to Josiah Carlson (who, in turn, gives credit to Nathan Fritz). Dr. Josiah was kind enough to provide all the details in here (this file is a part of a Python package that helps managing Lua scripts that call other scripts).

Itamar Haber
  • 47,336
  • 7
  • 91
  • 117
  • ugh that is so much more difficult than you describe it ... if it was not SO much more efficient I would not `lua` in redis at all. but it is so I must. – NappingRabbit Jan 18 '18 at 01:55
  • @NappingRabbit - undocumented means or should not be used :) what are you trying to do, or why? – Itamar Haber Jan 18 '18 at 12:22
  • I have actually rethought my encapsulation in the last 10 hours. heh. I was wanting to build up an object using lua in an object oriented way. no worries now. thanks for the response though – NappingRabbit Jan 18 '18 at 12:27
-1

You cannot do that. However violating EVAL semantics this way should not be a problem as long as you do not use Redis Cluster.

catwell
  • 6,770
  • 1
  • 23
  • 21