redis-lua脚本-无参-比较2个数值

以下是演变的过程:

eval 
"
return 'haha'
" 0 
eval 
"
local res = 'haha';
return res;
" 0 
eval 
"
local value1 = redis.call('get','value1');
local value2 = redis.call('get','value2');

return value1;
" 0 
eval 
"
return 1 < 2;
" 0 
eval " return 1 > 2; " 0
eval " return 1 < 2; " 0
eval " return tonumber('1'); " 0
eval 
"
local value1 = tonumber(redis.call('get','value1'));
local value2 = tonumber(redis.call('get','value2'));

return value1 > value2;
" 0 

最终的版本

前提是得之前得设置了value1和value2的数值,另外这些值需要是数值类型的,本来就要是对数值进行转换的不要给我整字符过来昂

eval 
"
local value1 = tonumber(redis.call('get','value1'));
local value2 = tonumber(redis.call('get','value2'));

return value2 > value1;
" 0 

end

你可能感兴趣的:(redis,lua)