【发布时间】:2012-06-08 16:54:25
【问题描述】:
我不知道 ruby,但我知道 python。运行以下代码的 python 等效项是什么?这个例子取自 redis 网站。那么,这是什么?
<<EOF?
它会在 python 中吗:
RandomPushScript = """
Lua code here
"""
RandomPushScript = <<EOF
local i = tonumber(ARGV[1])
local res
math.randomseed(tonumber(ARGV[2]))
while (i > 0) do
res = redis.call('lpush',KEYS[1],math.random())
i = i-1
end
return res
EOF
r.del(:mylist)
puts r.eval(RandomPushScript,1,:mylist,10,rand(2**32))
【问题讨论】:
-
抱歉,“用 Ruby 编写的 Lua 脚本”?? Lua 和 Ruby 是不同的语言,Python 是第三种。
-
@DanielRoseman 如上所见,它是一个 Ruby 脚本,似乎将 Lua 脚本创建为一个大字符串,然后对其进行处理。
-
很少有关于使用 redis 编写 lua 脚本的文档。确实存在的文档;它使用 ruby 将 lua 函数传递给 redis。对于python程序员来说,如果有python例子就好了。