从Redis客户端运行Lua脚本时出错 [英] Error while running Lua script from redis client

查看:1634
本文介绍了从Redis客户端运行Lua脚本时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Lua脚本中的"Hello World"程序. 我正在尝试从(巧克力)Redis客户端调用脚本. 我不断收到这个错误 (错误)ERR错误编译脚本(新函数):user_script:1:预期在'.'附近的函数参数.

I have the "Hello World" program in Lua script. I am trying to call the script from (Chocolatey) Redis client. I keep getting this error (error) ERR Error compiling script (new function): user_script:1: function argument expected near '.'

Redis脚本:"hello.lua"

local msg = "Hello, world!"
return msg

巧克力Redis客户端:

127.0.0.1:6379> EVAL "D:\hello.lua" 0

错误消息

(error) ERR Error compiling script (new function): user_script:1: function argument expected near '.'

推荐答案

EVAL 接受脚本本身,而不是文件名.

尝试一下:

EVAL 'local msg = "Hello, world!" return msg' 0

,以执行文件中的脚本,redis-cli提供--eval开关,您可以按以下方式使用该开关:

to execute a script in a file, redis-cli provides the --eval switch that you can use as follows:

redis-cli --eval <path-to-script-file> [key1 [key2] ...] , [arg1 [arg2] ...]

我对Windows fork不熟悉,但是它也应该得到它的支持.

I'm not familiar with the Windows fork, but it should be supported by it as well in all likelihood.

在* nix中,您还可以使用外壳程序将脚本的内容提供给cli,例如:

In *nix, you can also use the shell to provide the contents of the script to the cli, for example:

redis-cli SCRIPT LOAD "$(cat path-to-script-file)"

会将文件中的内容加载到Redis.在Windows中应该有类似的方法来实现这一点,但这超出了我当前的范围;)

will load the contents in the file to Redis. There should be a similar way for achieving this in Windows but that's outside my current scope ;)

这篇关于从Redis客户端运行Lua脚本时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆