redis.clients.jedis.exceptions.jedisdateexception:ERR错误编译脚本(新函数):user_脚本:1:附近的数字格式错误
我正在redis中编写一个lua脚本,并在spring中执行,内容非常简单redis.clients.jedis.exceptions.jedisdateexception:ERR错误编译脚本(新函数):user_脚本:1:附近的数字格式错误,exception,redis,lua,jedis,Exception,Redis,Lua,Jedis,我正在redis中编写一个lua脚本,并在spring中执行,内容非常简单 local store = redis.call('hget',KEYS[1],'capacity') print(store) if store <= 0 then return 0 end store = store - 1 redis.call('hset',KEYS[1],'capacity',store) redis.call('sadd',KEYS[2],ARGV[1]) return 1 我在r
local store = redis.call('hget',KEYS[1],'capacity')
print(store)
if store <= 0
then return 0
end
store = store - 1
redis.call('hset',KEYS[1],'capacity',store)
redis.call('sadd',KEYS[2],ARGV[1])
return 1
我在redis cli中尝试了以下脚本
eval "local s = tonumber(redis.call('hget',KEYS[1],'capacity')) return s" 1 001
它回来了
(integer) 100
Java代码如下所示:
String script ="local store = redis.call('hget',KEYS[1],'capacity')\n" +
"print(store)\n" +
"if store <= 0\n" +
"then return 0\n" +
"end\n" +
"store = store - 1\n" +
"redis.call('hset',KEYS[1],'capacity',store)\n" +
"redis.call('sadd',KEYS[2],ARGV[1])\n" +
"return 1\n" +
"\n";
if(sha==null){
sha = jedis.scriptLoad(script) ;
System.out.println("sha:"+sha);
}
Object ojb = jedis.eval(sha,2,id,userName,id) ;
String script=“local store=redis.call('hget',键[1],'capacity')\n+
“打印(存储)\n”+
“如果存储而不是绝地.eval
,你想使用它
您遇到的错误是Redis服务器试图将262b4ca69c1805485d135aa6298c2b00bc7c8c09
解释为实际脚本。若要调用以前加载的脚本,请使用。Wow,您太棒了。非常感谢。@Arrow.Tao,很高兴提供帮助,如果解决了您的问题,请将答案标记为已接受,然后进行投票如果你愿意
String script ="local store = redis.call('hget',KEYS[1],'capacity')\n" +
"print(store)\n" +
"if store <= 0\n" +
"then return 0\n" +
"end\n" +
"store = store - 1\n" +
"redis.call('hset',KEYS[1],'capacity',store)\n" +
"redis.call('sadd',KEYS[2],ARGV[1])\n" +
"return 1\n" +
"\n";
if(sha==null){
sha = jedis.scriptLoad(script) ;
System.out.println("sha:"+sha);
}
Object ojb = jedis.eval(sha,2,id,userName,id) ;