前言:
今天各位老铁们对“nginxluadebug输出”大概比较注重,各位老铁们都想要分析一些“nginxluadebug输出”的相关内容。那么小编在网络上汇集了一些关于“nginxluadebug输出””的相关知识,希望姐妹们能喜欢,你们快快来了解一下吧!调试redis+lua
学了lua的基本语法,了解了redis+lua的配套用法,但是却不知道怎么断点调试。学就学全面点, 官网中有dubug相关说明。地址:Redis Lua scripts debugger
基础
-- script.lualocal ping = redis.call('ping')return ping
# 执行脚本 --ldb --eval➜ 7Debug git:(main) ✗ redis-cli --ldb --eval /Users/mw/Desktop/Github/Integration/Redis/7Debug/script.luaLua debugging session started, please use:quit -- End the session.restart -- Restart the script in debug mode again.help -- Show Lua script debugging commands.* Stopped at 1, stop reason = step over# 调试位置-> 1 local ping = redis.call('ping')# nextlua debugger> n<redis> ping<reply> "+PONG"* Stopped at 2, stop reason = step over# 调试位置-> 2 return ping# 打印lua变量lua debugger> print ping<value> {["ok"]="PONG"}# nextlua debugger> n# lua返回的结果PONG# 调试结束(Lua debugging session ended -- dataset changes rolled back)# 退出redis-cli127.0.0.1:6379> exit➜ 7Debug git:(main) ✗
-- script1.lua-- 测试接受参数local src = KEYS[1]local dst = KEYS[2]local count = tonumber(ARGV[1])参数KEYS & ARGV
传递参数时的注意事项
# 传参数: list_a list_b 10➜ 7Debug git:(main) ✗ redis-cli --ldb --eval /Users/mw/Desktop/Github/Integration/Redis/7Debug/script1.lua list_a list_b 10Lua debugging session started, please use:quit -- End the session.restart -- Restart the script in debug mode again.help -- Show Lua script debugging commands.* Stopped at 1, stop reason = step over-> 1 local src = KEYS[1]# lua debugger> printNo local variables in the current context.# lua debugger> n* Stopped at 2, stop reason = step over-> 2 local dst = KEYS[2]# lua debugger> n* Stopped at 3, stop reason = step over-> 3 local count = tonumber(ARGV[1])# 打印 KEYS 全部都是keyslua debugger> print KEYS<value> {"list_a"; "list_b"; "10"}# 打印 ARGVlua debugger> print ARGV<value> {}# 结束lua debugger> n(integer) 1(Lua debugging session ended -- dataset changes rolled back)127.0.0.1:6379>
**参数 中 KEYS & ARGV 区分: 逗号隔开** 1. 参数`list_b,`, 逗号与key之间没有空格,则认为依旧是KEYS;
# 注意 ➜ 7Debug git:(main) ✗ redis-cli --ldb --eval /Users/mw/Desktop/Github/Integration/Redis/7Debug/script1.lua list_a list_b , 10Lua debugging session started, please use:quit -- End the session.restart -- Restart the script in debug mode again.help -- Show Lua script debugging commands.* Stopped at 1, stop reason = step over-> 1 local src = KEYS[1]# KEYSlua debugger> print KEYS<value> {"list_a"; "list_b"}# ARGVlua debugger> print ARGV<value> {"10"}lua debugger> lua debugger> n* Stopped at 2, stop reason = step over-> 2 local dst = KEYS[2]lua debugger> n* Stopped at 3, stop reason = step over-> 3 local count = tonumber(ARGV[1])lua debugger> n* Stopped at 4, stop reason = step over-> 4 return true#lua debugger> print<value> src = "list_a"<value> dst = "list_b"<value> count = 10lua debugger> n(integer) 1(Lua debugging session ended -- dataset changes rolled back)127.0.0.1:6379>队列操作
将list_a中的一个元素push到list_b
➜ 7Debug git:(main) ✗ redis-cli --ldb --eval /Users/mw/Desktop/Github/Integration/Redis/7Debug/script1.lua list_a list_b , 10Lua debugging session started, please use:quit -- End the session.restart -- Restart the script in debug mode again.help -- Show Lua script debugging commands.* Stopped at 1, stop reason = step over-> 1 local src = KEYS[1]# 打印keyslua debugger> print KEYS<value> {"list_a"; "list_b"}# 打印参数lua debugger> print ARGV<value> {"10"}# 初始化队列 list_a、list_blua debugger> r lpush list_a 1 2 3 4 <redis> lpush list_a 1 2 3 4<reply> 4lua debugger> r lpush list_b a b c d<redis> lpush list_b a b c d<reply> 4lua debugger> n* Stopped at 2, stop reason = step over-> 2 local dst = KEYS[2]lua debugger> n* Stopped at 3, stop reason = step over-> 3 local count = tonumber(ARGV[1])lua debugger> n* Stopped at 5, stop reason = step over-> 5 local item = redis.call('rpop', src)# next 执行poplua debugger> n<redis> rpop list_a<reply> "1"* Stopped at 6, stop reason = step over-> 6 redis.call('lpush', dst, item)# next 执行pushlua debugger> n<redis> lpush list_b 1<reply> 5* Stopped at 7, stop reason = step over-> 7 return true# r: redis; 获取list元素lua debugger> r lrange list_a 0 -1<redis> lrange list_a 0 -1<reply> ["4","3","2"]# r: redis; 获取list元素lua debugger> r lrange list_b 0 -1<redis> lrange list_b 0 -1# 执行成功<reply> ["1","d","c","b","a"]# 重启,将所有执行回滚lua debugger> restartLua debugging session started, please use:quit -- End the session.restart -- Restart the script in debug mode again.help -- Show Lua script debugging commands.* Stopped at 1, stop reason = step over-> 1 local src = KEYS[1]# 回滚至无数据lua debugger> r lrange list_b 0 -1<redis> lrange list_b 0 -1<reply> []lua debugger>断点调试
断点操作
# 写入redis 准备数据➜ 7Debug git:(main) ✗ redis-cli127.0.0.1:6379> lpush list_a 1 2 3 4(integer) 4127.0.0.1:6379> lpush list_b a b c d(integer) 4127.0.0.1:6379> llen list_a(integer) 4127.0.0.1:6379> llen list_b(integer) 4127.0.0.1:6379>
# 获取全部文件lua debugger> w 1 local src = KEYS[1] 2 local dst = KEYS[2] 3 local count = tonumber(ARGV[1]) 4 -> 5 while count < 10 do 6 local item = redis.call('rpop', src) 7 if item == false then break end 8 redis.call('lpush', dst, item) 9 count = count -1 10 end 11 12 return redis.call('llen', dst);# 显示第7行 【l:list】lua debugger> l 7 2 local dst = KEYS[2] 3 local count = tonumber(ARGV[1]) 4 -> 5 while count < 10 do 6 local item = redis.call('rpop', src) 7 if item == false then break end 8 redis.call('lpush', dst, item) 9 count = count -1 10 end 11 12 return redis.call('llen', dst);# 显示第7行前后一行 【l:list】lua debugger> l 7 1 6 local item = redis.call('rpop', src) 7 if item == false then break end 8 redis.call('lpush', dst, item)lua debugger> b 6-> 5 while count < 10 do #6 local item = redis.call('rpop', src) 7 if item == false then break end# continue 继续,直到断点执行lua debugger> c(integer) 4(Lua debugging session ended -- dataset changes rolled back)127.0.0.1:6379>逐步断点
lua debugger> w-> 1 local src = KEYS[1] 2 local dst = KEYS[2] 3 local count = tonumber(ARGV[1]) 4 5 while count > 0 do 6 local item = redis.call('rpop', src) 7 if item == false then break end 8 redis.call('lpush', dst, item) 9 count = count -1 10 end 11 12 return redis.call('llen', dst);lua debugger> b 8 7 if item == false then break end #8 redis.call('lpush', dst, item) 9 count = count -1# 验证断点位置lua debugger> w-> 1 local src = KEYS[1] 2 local dst = KEYS[2] 3 local count = tonumber(ARGV[1]) 4 5 while count > 0 do 6 local item = redis.call('rpop', src) 7 if item == false then break end #8 redis.call('lpush', dst, item) 9 count = count -1 10 end 11 12 return redis.call('llen', dst);# 等同与nextlua debugger> c* Stopped at 8, stop reason = break point->#8 redis.call('lpush', dst, item)lua debugger> print<value> src = "list_a"<value> dst = "list_b"<value> count = 10<value> item = "1"lua debugger> c* Stopped at 8, stop reason = break point->#8 redis.call('lpush', dst, item)lua debugger> c* Stopped at 8, stop reason = break point->#8 redis.call('lpush', dst, item)lua debugger> c* Stopped at 8, stop reason = break point->#8 redis.call('lpush', dst, item)# 打印日志lua debugger> print<value> src = "list_a"<value> dst = "list_b"<value> count = 7<value> item = "4"redis.debug 一步到位
此处有加新代码:redis.debug('dubug value:', item)
lua debugger> w-> 1 local src = KEYS[1] 2 local dst = KEYS[2] 3 local count = tonumber(ARGV[1]) 4 5 while count > 0 do 6 local item = redis.call('rpop', src)# 采用redis.debug 7 redis.debug('dubug value:', item) 8 if item == false then break end 9 redis.call('lpush', dst, item) 10 count = count -1 11 end 12 13 return redis.call('llen', dst);# 继续,打印redis.debug处的日志lua debugger> c<debug> line 7: "dubug value:", "1"<debug> line 7: "dubug value:", "2"<debug> line 7: "dubug value:", "3"<debug> line 7: "dubug value:", "4"<debug> line 7: "dubug value:", false(integer) 8(Lua debugging session ended -- dataset changes rolled back)127.0.0.1:6379>
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #nginxluadebug输出