随笔分类 -  Lua

摘要:怎么引用同级目录的自定义公共模块 方法 1:修改 lua_package_path 包含当前目录(推荐)​ 在 ​​Nginx 配置​​ 中添加以下指令: http { # 添加当前目录到 Lua 模块搜索路径 lua_package_path "/app/openresty/nginx/conf/ 阅读全文
posted @ 2025-07-08 17:55 醒日是归时 阅读(30) 评论(0) 推荐(0)
摘要:安装版本 # lua -v Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio # apisix version /usr/local/openresty//luajit/bin/luajit /usr/local/apisix/apisix/cli 阅读全文
posted @ 2024-06-06 14:36 醒日是归时 阅读(125) 评论(0) 推荐(0)
摘要:读写文件的模式 r - 读取模式w - 写入模式(覆盖现有内容) a - 附加模式(附加在现有内容之后) b - 二进制模式 r+ - 读取更新模式(现有数据保留) w+ - 写入更新模式(现有数据擦除) a+ - 附加更新模式(现有数据保留,只在文件末尾附加) do --read data fro 阅读全文
posted @ 2023-12-27 17:59 醒日是归时 阅读(189) 评论(0) 推荐(0)
摘要:背景 为网关提供健康检查功能时需要对节点发送http或者tcp探活请求。Openresty 提供cosocket来处理非阻塞IO。 实现 跟工程结合在一起,这里简单拼接数据结构 local function __default_check_alive(status) return status >= 阅读全文
posted @ 2023-12-20 16:26 醒日是归时 阅读(131) 评论(0) 推荐(0)
摘要:[TOC] # 插件开发 此文档是关于 lua 语言的插件开发,其他语言请看:external plugin。 ## 插件放置路径 Apache APISIX 提供了两种方式来添加新的功能。 修改 Apache APISIX 的源代码并重新发布 (不推荐)。 配置 extra_lua_path 和 阅读全文
posted @ 2023-08-23 14:35 醒日是归时
摘要:luasql 编译安装 查看mysql配置,注意 lmysqlclient 路径 [root@hmy luasql-master]# yum install mysql-devel gcc* -y [root@hmy luasql-master]# mysql_config Usage: /usr/ 阅读全文
posted @ 2022-09-19 00:43 醒日是归时 阅读(165) 评论(0) 推荐(0)
摘要:今天遇到一个麻烦的问题,查询redis时候,查到数据的时候正常返回,查询不到数据时,返回了null,然而在lua中,常见的nil,但不常见null,这时候lua中对redis返回的null如何做判断呢?于是各种尝试。这是经过公司基础库封装的结果,并非官方的返回,redis返回结果如下: {"retm 阅读全文
posted @ 2022-07-01 01:05 醒日是归时 阅读(1055) 评论(0) 推荐(0)
摘要:-- 获取请求路径 local request_uri = ngx.var.request_uri -- 从 header中取值 local token = ngx.req.get_headers()["token"] -- 获取cookie中的值 local user_id = ngx.var.c 阅读全文
posted @ 2022-06-30 22:33 醒日是归时 阅读(1969) 评论(0) 推荐(0)
摘要:1. 利用string库的gsub函数 function split( str,reps ) local resultStrList = {} string.gsub(str,'[^'..reps..']+',function ( w ) table.insert(resultStrList,w) 阅读全文
posted @ 2022-06-30 18:32 醒日是归时 阅读(1130) 评论(0) 推荐(0)