for i, name in ipairs(redis.call('KEYS''cache:user_transaction_logs:*:8866666')) do redis.call('DEL', name); end"
Run Code Online (Sandbox Code Playgroud)
如何优化此redis查询?
我们在Rails中使用Redis作为缓存存储.每当auser进行成功的事务时,接收者和发起者的事务历史记录从redis到期
我创建了基本的lua脚本,除了一个参数并打印它的值,使用redis-cli执行它没有错误,o/p打印在日志文件中.
$ cat test.lua
redis.replicate_commands()
local var = ARGV[1]
print ( 'var ', var)
$ redis-cli --eval test.lua , A
nil
$
Run Code Online (Sandbox Code Playgroud)
我想使用perl脚本运行lua脚本:
$ cat eval.pl
#!/usr/bin/perl
use strict;
use warnings;
use Redis;
my $r = Redis->new(
server => '127.0.0.1:6379',
reconnect => 3,
every => 1.5 * 1000000,
conservative_reconnect => 1,
no_auto_connect_on_new => 1,
cnx_timeout => 15,
);
eval {
$r->connect;
};
if ($@) {
print '$@ : '.$@;
}
my $result = $r->eval( "test.lua", 0, 'A' );
print "result …Run Code Online (Sandbox Code Playgroud) 
--t.lua
function fact(n)
if n == 0 then
return 1
else
return n * fact(n-1)
end
end
for i=1,100,1 do
print(i,fact(i))
end
Run Code Online (Sandbox Code Playgroud)
# t.py
fact = lambda n:1 if n == 0 else n * fact(n-1)
for i in range(1, 100):
print(i, fact(i))
Run Code Online (Sandbox Code Playgroud)
当我在Lua和Python中编写析因代码时,我发现输出是不同的.
我对如何获得以下结果感到困惑.如果mod应该返回"余数".以下是lua翻译结果.
> 278 % 1
0
> 278 % 2
0
> 278 % 3
2
> 278 % 4
2
> 278 % 5
3
> 278 % 6
2
> 278 % 7
5
> 278 % 8
6
> 278 % 9
8
> 278 % 20
18
> math.fmod(278,20)
18
Run Code Online (Sandbox Code Playgroud) 当我运行我的lua代码时,我得到了'end'附近的错误'name' 12号线
这是代码:
local i = 1
local plr = game.Players.LocalPlayer
function start()
repeat
wait()
game.ReplicatedStorage.addpoints:FireServer()
until i == 2
end
function end()
i = 2
end
plr.Chatted:connect(function(message)
if message == "start" then
start()
elseif message == "end" then
end()
end
end)
Run Code Online (Sandbox Code Playgroud)
任何修复?
我在这里找到了柠檬的Lua 5.1语法(页面末尾的清单1):
%fallback OPEN '(' .
chunk ::= block .
semi ::= ';' .
semi ::= .
block ::= scope statlist .
block ::= scope statlist laststat semi .
ublock ::= block 'until' exp .
scope ::= .
scope ::= scope statlist binding semi.
statlist ::= .
statlist ::= statlist stat semi .
stat ::= 'do' block 'end' .
stat ::= 'while' exp 'do' block 'end' .
stat ::= repetition 'do' block 'end' .
stat ::= 'repeat' ublock …Run Code Online (Sandbox Code Playgroud) 所以我有一些Lua字节码,现在我想把它重新编译成人类可读的代码:
\27\76\117\97\81\0\1\4\8\4\8\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\2\2\4\0\0\0\5\0\0\0\65\64\0\0\28\64\0\1\30\0\128\0\2\0\0\0\4\6\0\0\0\0\0\0\0\112\114\105\110\116\0\4\9\0\0\0\0\0\0\0\72\105\32\116\104\101\114\101\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0
Run Code Online (Sandbox Code Playgroud)
我怎么做到这一点?我尝试过使用LuaDec,但是我收到以下错误:
预编译块中的错误标头
如果有人能帮助我那将是非常好的.
我不能math.pow(x,y)在Lua中使用。
我不知道为什么,它说语法错误。
math.sin(f)并且math.cos(f)有效。
math.pow()在Lua中还有其他选择吗?
My question:
How to call a python script from C++?
Context:
I have such line written in Lua language:
os.execute("C:\\InstallPython\\python.exe C:\\FINAM\\py+lua\\Finam_parser.py")
Run Code Online (Sandbox Code Playgroud)
It runs a python script from my Lua script. Now, I want to transfer this script from Lua to C++. Please, help me to write the same thing using C++ language and to include the proper libraries.