本文介绍了Redis Lua脚本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个redis lua脚本来执行基于关键数据类型的命令:-

I have created a redis lua script to execute a command based on key data type :-

local keyType = redis.call("TYPE", KEYS[1])
if (keyType == "string")
then
return redis.call("GET",KEYS[1])
else
return nil
end

每次执行它都会返回null.请帮助纠正脚本.

It is returning null every time I am executing it.Can any please help in correcting the script.

推荐答案

redis.call的响应将返回如下表:{"ok": "string"}(如果类型为字符串)

The response to redis.call returns as a table that looks like this: {"ok": "string"} (if the type is a string of course)

因此,为了正确检查,您应该将代码更改为:

So in order to properly check, you should change your code to:

local keyType = redis.call("TYPE", KEYS[1]).ok

,其余代码将正常工作.

and the rest of the code will work fine.

问题是这样的:TYPE命令是少数几个返回简单字符串"或状态" redis答复的命令之一(请参见 redis协议规范(用于响应类型).在redis lua文档中指出:

The issue is this: the TYPE command is one of the few commands that return a "simple string" or "status" redis reply (see the redis protocol specs for the response types). In the redis lua documentation it's stated that:

这是怎么回事.

这篇关于Redis Lua脚本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 03:14