redisson中使用lua腳本的問(wèn)題
起因
事情是這樣的,我在通過(guò)redission進(jìn)行限流時(shí),用到了在lua腳本里進(jìn)行數(shù)值計(jì)算,而我在本地測(cè)試過(guò)程中,發(fā)現(xiàn)所有tonumber()方法時(shí),返回值都是nil,這個(gè)原因最后找到了,是沒(méi)有配置序列化的方式,出現(xiàn)錯(cuò)誤提示如下:
org.redisson.client.RedisException: ERR Error running script (call to f_189758df5f16d279fa4852c3ee51f702e4ea0414): @user_script:1: user_script:1: attempt to perform arithmetic on a nil value . channel: [id: 0x850f178a, L:/127.0.0.1:54544 - R:localhost/127.0.0.1:6379] command: (EVAL), promise: java.util.concurrent.CompletableFuture@2f42a4b1[Not completed, 1 dependents], params: [return tonumber(ARGV[1]) + tonumber(ARGV[2]), 1, a, PooledUnsafeDirectByteBuf(ridx: 0, widx: 2, cap: 256), PooledUnsafeDirectByteBuf(ridx: 0, widx: 2, cap: 256)]
解決方法
找到了原因,解決就變得很容易了,我們添加jackson序列化就可以了

lua測(cè)試代碼

