执行redis服务器的lua脚本时出错

Rag*_*ngh 6 lua redis

我正在按照这个简单的教程来试用一个简单的lua脚本

http://www.redisgreen.net/blog/2013/03/18/intro-to-lua-for-redis-programmers/

我用这些行创建了一个简单的hello.lua文件

local msg = "Hello, world!"
return msg
Run Code Online (Sandbox Code Playgroud)

我试着运行简单的命令

EVAL "$(cat /Users/rsingh/Downloads/hello.lua)" 0
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

(error) ERR Error compiling script (new function): user_script:1: unexpected symbol near '$' 
Run Code Online (Sandbox Code Playgroud)

我找不到这里有什么问题,我找不到遇到过这个问题的人.

任何帮助将深表感谢.

del*_*eil 8

您的问题来自于您从交互式 Redis会话执行此命令的事实:

$ redis-cli
127.0.0.1:6379> EVAL "$(cat /path/to/hello.lua)" 0
(error) ERR Error compiling script (new function): user_script:1: unexpected symbol near '$'
Run Code Online (Sandbox Code Playgroud)

在这样的会话中,您不能使用常见的命令行工具,如catet al.(这里cat用作获取脚本内容的便捷方式).换句话说:你"$(cat /path/to/hello.lua)"作为一个普通字符串发送给Redis,这不是Lua代码(当然),Redis抱怨.

要执行此示例,您必须保留在shell中:

$ redis-cli EVAL "$(cat /path/to/hello.lua)" 0
"Hello, world!"
Run Code Online (Sandbox Code Playgroud)