Refactoring lua scripts

Skip to first unread message

Ambar Sarkar

Sep 13, 2021, 9:24:11 PMSep 13
to Redis DB
I have a bunch of lua scripts that have lot of code in common. What are some of the ways once can reduce code duplication? 

I tried using the require keyword, and even tried calling evalsha from my lua scripts, but those approaches did not work. 

When I use require, I get the following error:
@enable_strict_lua:15: user_script:31: Script attempted to access nonexistent global variable 'require'

When I registered the common script and tried using the sha1 in an evalsha command from within my lua script, I get the error message :
This Redis command is not allowed from scripts

All I am looking to do is avoid code duplication in the redis lua scripts and improve maintainability.  Ideas/suggestions appreciated. 


Narendra Kumar

Sep 14, 2021, 12:52:10 AMSep 14

You can create a method/function for common code, in your lua script and call them where-ever required.


You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

This E-mail message is private and confidential and should only be read by those to whom it is addressed. If you are not the intended recipient, you are hereby notified that any dissemination, distribution, copying, reproduction, modification or publication of this communication is strictly prohibited. Please delete the message from your computer and destroy any copies. This message is not intended to be relied upon by any person without disclaims all responsibility and accepts no liability of any kind which may arise from any person acting or refraining from acting, upon the contents of the message without having had subsequent written confirmation. If you have received this communication in error, or if any problems occur in transmission please notify us immediately on email to

Ambar Sarkar

Sep 14, 2021, 12:20:31 PMSep 14
Thanks, but how do you share this code between various .lua scripts in Redis?

Ambar Sarkar:
Skype:             ambar.sarkar
Reply all
Reply to author
0 new messages