February 2018
Intermediate to advanced
382 pages
11h 33m
English
Let's take the Lua script introduced in the previous recipe to show how to debug a Lua script of Redis as an example:
$ mkdir /redis/coding/lua; cd /redis/coding/lua
$ cat updatejsondebug.lua
local id = KEYS[1]
local data = ARGV[1]
redis.debug(id)
redis.debug(data)
local retJson = redis.call('get', id)
local dataSource = cjson.decode(data)
if retJson == false then
retJson = {}
else
retJson = cjson.decode(retJson)
end
redis.breakpoint()
for k,v in pairs(dataSource) do
retJson[k] = v
end
redis.log(redis.LOG_WARNING,cjson.encode(retJson))
redis.call('set', id, cjson.encode(retJson))
return redis.call('get',id)
$ bin/redis-cli ...
Read now
Unlock full access