在CentOS 6.9 x86_64上玩转OpenResty 1.13.6.1中的resty-cli模块

resty-cli是OpenResty中命令行工具的集合,其中resty工具是最有用的。

安装好OpenResty之后,resty-cli就会默认安装,以我的安装为例,参见博文

http://blog.csdn.net/tao_627/article/details/78912545

它的位置在/opt/openresty/bin下面



前提条件

OpenResty 1.7.7.2+


配置环境变量

vim /etc/profile

将末尾添加进目录/opt/openresty/bin

export PATH=/opt/openresty/nginx/sbin:/opt/openresty/bin:$PATH

保存退出,然后运行下面的命令生效

source /etc/profile

执行下面的命令检查

echo $PATH



安装依赖库

yum -y install perl-Time-HiRes

原因参见博文

http://blog.csdn.net/tao_627/article/details/78919286
然后我们可以查看resty的路径和版本号

resty -h

resty -v




业务需求
通常我们验证nginx_lua中的脚本,或者调试lua相关代码片段,或者了解ngx.md5之类函数的用法等,只能通过加入nginx.conf中的配置,在nginx框架上玩。
但是这未免比较不便,如果我们有一个命令行工具类似lua, luajit, python等直接执行该多好啊。那么这里的resty就是你想要的工具。

测试样例

下面的几个例子都是来自resty-cli模块的官网

resty -e 'print("hello world")'

time resty -e 'ngx.sleep(3) print("done\n")'

resty -e 'ngx.say(ngx.md5("hello"))'

resty -e 'io.stderr:write("hello world\n")' > /dev/null


更深入的例子及高深玩法有待后续继续挖掘

resty -e 'print("got: ", io.stdin:read("*l"))'


其中taoyunxing是我从键盘输入的内容。

time resty -e 'local ths = {}
                 for i = 1, 3 do
                     ths[i] = ngx.thread.spawn(function ()
                                  ngx.sleep(3) ngx.say("done ", i)
                              end)
                 end
                 for i = 1, #ths do ngx.thread.wait(ths[i]) end'


resty --shdict='dogs 1m' -e 'local dict = ngx.shared.dogs
                               dict:set("Tom", 56)
                               print(dict:get("Tom"))'



参考文献

[1].https://openresty.org/cn/resty-cli.html

[2].https://github.com/openresty/resty-cli#readme

[3].

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值