Refactoring lua scripts

283 views
Skip to first unread message

Ambar Sarkar

unread,
Sep 13, 2021, 9:24:11 PM9/13/21
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. 

Thanks,
-Ambar

Narendra Kumar

unread,
Sep 14, 2021, 12:52:10 AM9/14/21
to redi...@googlegroups.com
Hi,

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

Regards
Narendra



--
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 redis-db+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/f341fc1d-6128-477b-a9b7-54e8080ec988n%40googlegroups.com.


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

unread,
Sep 14, 2021, 12:20:31 PM9/14/21
to redi...@googlegroups.com
Thanks, but how do you share this code between various .lua scripts in Redis?



--
Ambar Sarkar:  ambar....@gmail.com
Skype:             ambar.sarkar
Reply all
Reply to author
Forward
0 new messages