how to load lua script from file for redis,i use linux

5113 views
Skip to first unread message

min Zhou

unread,
Jun 16, 2012, 1:40:18 PM6/16/12
to redi...@googlegroups.com
how to load lua script from file for redis,i use linux

Dvir Volk

unread,
Jun 16, 2012, 1:43:36 PM6/16/12
to redi...@googlegroups.com
short answer - you can't. redis accepts lua scripts as strings. if you want to load lua files, you'll need to create a convenience wrapper yourself using your favorite programming language.

On Sat, Jun 16, 2012 at 8:40 PM, min Zhou <zm42...@gmail.com> wrote:
how to load lua script from file for redis,i use linux

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To view this discussion on the web visit https://groups.google.com/d/msg/redis-db/-/aGV-H0W-EbAJ.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Chris Love

unread,
Jun 20, 2012, 12:18:06 PM6/20/12
to redi...@googlegroups.com
min

What programming language do you use? It is recommended to embed the script into the client language you are using and then execute an eval.

Chris

min Zhou

unread,
Jun 20, 2012, 12:32:51 PM6/20/12
to redi...@googlegroups.com
nodejs ,javascript .

i don't konw how to load a long script to redis,i want write lua script file,and then use "script load" command load this file ,but it doesn't work


在 2012年6月17日星期日UTC+8上午1时40分18秒,min Zhou写道:

Chris Love

unread,
Jun 20, 2012, 12:34:14 PM6/20/12
to redi...@googlegroups.com
You have said that you are using javascript & node.js.

Take a look at this example:


You need to use the node_redis client and run an eval with-in javascript.

Chris

Chris Love

unread,
Jun 20, 2012, 12:47:20 PM6/20/12
to redi...@googlegroups.com
It is usually not recommend to run the load script command and then run the script.

The recommended pattern is to run the evalsha, and if that fails, run the eval.  In that manner your script will be loaded and you can reuse it.

Otherwise you have to find a client application that will allow you to run a script load command. You may be able to use the script load redis-cli command, not in the shell but one the command line.  Never done it.

Chris

min Zhou

unread,
Jun 20, 2012, 12:47:40 PM6/20/12
to redi...@googlegroups.com
T_T  e文差好痛苦

i can run eval in the node_redis client;

i just didn't konw how to load a long script use "script load" command,


a.lua is lua script
>dd=`cat a.lua`
>./redis-cli
redis 127.0.0.1:6379>script load $dd


it doesn't work

在 2012年6月17日星期日UTC+8上午1时40分18秒,min Zhou写道:
how to load lua script from file for redis,i use linux

Alex Barker

unread,
Jun 18, 2015, 8:58:02 AM6/18/15
to redi...@googlegroups.com
Here is a cute little 1 liner i found at https://www.redisgreen.net/blog/intro-to-lua-for-redis-programmers/
redis-cli EVAL "$(cat hello.lua)" 0

Itamar Haber

unread,
Jun 18, 2015, 1:58:59 PM6/18/15
to redi...@googlegroups.com

Sure, that works, but true Redis Masters use `redis-cli --eval file.lua k1 k2 , arg1 arg2` ;)

--
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 post to this group, send email to redi...@googlegroups.com.
Visit this group at http://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages