Redis Lua脚本报错 redis() command arguments must be strings or integers

Redis artisan 721℃ 0评论

初次使用lua语言的写Redis脚本犯的低级错误,记下吸取一下教训。

127.0.0.1:6379>   EVAL  "local member =  redis.call('ZRANGE', KEYS[1], 0, 0) if (next(member)==nil)  then  return member else redis.call('ZREM', KEYS[1], member)  return member  end "  1  tq
(error) ERR Error running script (call to f_b664f6390b105f30f17c6a39383611efe86f7bf8): @user_script:1: @user_script: 1: Lua redis() command arguments must be strings or integers

开启Redis debugger进行调试lua脚本,命令如下:

redis-cli –ldb –eval  fuck.lua    tq

错误解析:

 redis.call('ZREM', KEYS[1], member)

ZREM第三个参数member是一个table类型,修改成integer或者string即可。tips:

127.0.0.1:6379> EVAL  "local member =  redis.call('ZRANGE', KEYS[1], 0, 0)  return  type(member) "  1 tq1
"table"

可以使用lua的type函数打印出类型信息进行排查问题,修改如下即可:

eval  "local member =  redis.call('ZRANGE', KEYS[1], 0, 0) if (next(member)==nil)  then  return member else redis.call('ZREM', KEYS[1], member[1])  return member  end  return member " 1 tq

转载请注明:Java工匠师 » Redis Lua脚本报错 redis() command arguments must be strings or integers

喜欢 (6)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址