1. lua入门demo

1.1. 入门之Hello World!!

  1. 由于我习惯用docker安装各种软件,这次的lua脚本也是运行在docker容器上
  2. openresty是nginx+lua的各种模块,所以直接docker安装openresty
  3. 修改nginx.conf配置文件,在http模块中加上
lua_package_path "/usr/local/openresty/lualib/?.lua;;";
  1. http内的server模块上,在加个
location /lua-file{
default_type 'text/html';
content_by_lua_file /usr/local/openresty/demo/lua-file.lua;
}
  1. 这样我可以在指定目录开始编写lua脚本了,在写完脚本后,nginx -s reload 一下就可以通过ip/lua-file访问lua脚本了

  2. 我在lua-file.lua内先写上 ngx.say('Hello world!!'),然后reload一下后

  3. 访问结果:

1.2. 访问redis

local function close_redis(red)
if not red then
return
end
local pool_max_idle_time = 10000
local pool_size = 100
local ok,err = red:set_keepalive(pool_max_idle_time,pool_size)
if not ok then
ngx.say("set keepalive error:" ,err)
end
end local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000)
local ok,err = red:connect("47.96.64.100",6379)
if not ok then
ngx.say("connect to redis error: ",err)
return close_redis(red)
end local count,err = red:get_reused_times()
if 0 == count then
ok,err = red:auth("123456")
if not ok then
ngx.say("auth fail")
return
end
elseif err then
ngx.say("failed to get reused times: ",err)
return
end ngx.say(red:get("dog"))
close_redis(red)
  1. 当然,我事先redis存放了key为dog的值
  2. 访问浏览器结果

1.3. 总结

  1. 通过简单的hello world实例和redis读取,我们基本了解了lua的用法和功能,lua的语法和js类似,部分自己的特色,这里我就抛砖引玉一下了

lua入门demo(HelloWorld+redis读取)的更多相关文章

  1. lua模块demo(redis,http,mysql,cjson,本地缓存)

    1. lua模块demo(redis,http,mysql,cjson,本地缓存) 1.1. 配置 在nginx.conf中设置lua_shared_dict my_cache 128m; 开启ngi ...

  2. Dubbo(五) Dubbo入门demo——helloworld

    前言 前面我已经介绍了dubbo的一些基本工具和知识,让大家简单的了解了下RPC框架和Dubbo.接下来就是重点了,Dubbo的helloworld项目. 一.搭建项目 首先我们新建三个maven项目 ...

  3. Redis快速入门:初识Redis

    [IT168 专稿]在之前的文章中介绍了<Redis快速入门:选择Key-Value Store>,今天给大家介绍Redis的入门知识.Redis是一个开源的使用ANSI C语言编写.支持 ...

  4. apollo入门demo实战(二)

    1. apollo入门demo实战(二) 1.1. 下载demo 从下列地址下载官方脚本和官方代码 https://github.com/nobodyiam/apollo-build-scripts ...

  5. C#中缓存的使用 ajax请求基于restFul的WebApi(post、get、delete、put) 让 .NET 更方便的导入导出 Excel .net core api +swagger(一个简单的入门demo 使用codefirst+mysql) C# 位运算详解 c# 交错数组 c# 数组协变 C# 添加Excel表单控件(Form Controls) C#串口通信程序

    C#中缓存的使用   缓存的概念及优缺点在这里就不多做介绍,主要介绍一下使用的方法. 1.在ASP.NET中页面缓存的使用方法简单,只需要在aspx页的顶部加上一句声明即可:  <%@ Outp ...

  6. ORM----hibernate入门Demo(无敌详细版)

    一.Hibernate(开放源代码的对象关系映射框架)简介: Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全 ...

  7. storm入门demo

    一.storm入门demo的介绍 storm的入门helloworld有2种方式,一种是本地的,另一种是远程. 本地实现: 本地写好demo之后,不用搭建storm集群,下载storm的相关jar包即 ...

  8. Mybatis入门Demo(单表的增删改查)

    1.Mybatis 什么是Mybatis: mybatis是一个持久层框架,用java编写的 它封装了jdbc操作的很多细节,使开发者只需要关注sql语句本身,而无需关注注册驱动.创建连接等繁杂过程 ...

  9. windows下使用redis,Redis入门使用,Redis基础命令

    windows下使用redis,Redis入门使用,Redis基础命令 >>>>>>>>>>>>>>>> ...

随机推荐

  1. Pytorch之训练器设置

    Pytorch之训练器设置 引言 深度学习训练的时候有很多技巧, 但是实际用起来效果如何, 还是得亲自尝试. 这里记录了一些个人尝试不同技巧的代码. tensorboardX 说起tensorflow ...

  2. hdfs数据采集场景示意图

  3. -bash: /etc/profile: line 11: syntax error near unexpected token `$'{\r''报错问题解决

    在Linux系统配置Java环境变量之后执行 source /etc/profile指令报:-bash: /etc/profile: line 11: syntax error near unexpe ...

  4. java pdf转word 高效不失真

    将java工程导成jar包 使用 bat 执行 jar 包. --------------------------------------------------------------------- ...

  5. ubuntu16.04安装tensorflow1.3

    总结 : 1.点软件个更新-系统更新2.降级gcc到5.33.装CUDA及第二个包,加入PATH4.CUDNN5.Ancada..6.TF Ubuntu16.04 的GCC版本降级 http://bl ...

  6. 图解HTTP第七章

    确保 Web 安全的HTTPS 1>HTTP 的缺点 通信使用明文可能会被窃听: [1]TCP/IP 是可能被窃听的网络 [2]加密处理防止被窃听: *通信的加密:通过和 SSL(Secure ...

  7. 小程序跳转tabbar页面

    如果在app.json 配置tabbar 的时候配置了 跳转的页面的链接: 在其余的子页面,设置用navigator 进行跳转会发现 在tabbar 设置过的页面无法进行跳转,这时需要在navigat ...

  8. docker私库Harbor部署(转载)

    系统环境 centos7.3docker-ce docker version: 18.03.0docker-compose version: 1.21.0 Install Docker CE 安装依赖 ...

  9. vim编辑器中没有高亮显示,退格键不能使用的问题

    在~/.vimrc下添加如下内容,立即生效

  10. js unicode转中文 &#26041;&#26696;&#27010;&#36848;&#32852;&#32593;LED&#29031;&#26126;&#26041;&#26696;&#21487;&#25191;&#34892;&#20840;&#37096;&#30340;DALI &#21644;

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...