[nginx]lua操作redis
- local redis = require "resty.redis"
- local red = redis:new()
- red:set_timeout() -- sec
- -- or connect to a unix domain socket file listened
- -- by a redis server:
- -- local ok, err = red:connect("unix:/path/to/redis.sock")
- local ok, err = red:connect("127.0.0.1", )
- if not ok then
- ngx.say("failed to connect: ", err)
- return
- end
- ok, err = red:set("dog", "an animal")
- if not ok then
- ngx.say("failed to set dog: ", err)
- return
- end
- ngx.say("set result: ", ok)
- local res, err = red:get("dog")
- if not res then
- ngx.say("failed to get dog: ", err)
- return
- end
- if res == ngx.null then
- ngx.say("dog not found.")
- return
- end
- ngx.say("dog: ", res)
- red:init_pipeline()
- red:set("cat", "Marry")
- red:set("horse", "Bob")
- red:get("cat")
- red:get("horse")
- local results, err = red:commit_pipeline()
- if not results then
- ngx.say("failed to commit the pipelined requests: ", err)
- return
- end
- for i, res in ipairs(results) do
- if type(res) == "table" then
- if res[] == false then
- ngx.say("failed to run command ", i, ": ", res[])
- else
- -- process the table value
- end
- else
- -- process the scalar value
- end
- end
- -- put it into the connection pool of size ,
- -- with seconds max idle time
- local ok, err = red:set_keepalive(, )
- if not ok then
- ngx.say("failed to set keepalive: ", err)
- return
- end
- -- or just close the connection right away:
- -- local ok, err = red:close()
- -- if not ok then
- -- ngx.say("failed to close: ", err)
- -- return
- -- end
- ';
[nginx]lua操作redis的更多相关文章
- 使用Nginx Lua实现redis高性能http接口
使用Nginx Lua实现redis高性能http接口 时间 -- :: 峰云就她了 原文 http://xiaorui.cc/2015/01/27/使用nginx-lua实现redis高性能http ...
- nginx lua mysql redis设置
最近公司网站改版,程序和数据库全部用新版,旧版的数据要导入,旧网站的30万条数据url要全部重定向到新版网站,正好前段时间在学习nginx+lua+mysql+memcache(redis),找资料真 ...
- lua 操作redis
Redis在2.6推出了脚本功能,允许开发者使用Lua语言编写脚本传到Redis中执行.使用脚本的好处如下: 1.减少网络开销:本来5次网络请求的操作,可以用一个请求完成,原先5次请求的逻辑放在red ...
- Nginx+Lua+MySQL/Redis实现高性能动态网页展现
Nginx结合Lua脚本,直接绕过Tomcat应用服务器,连接MySQL/Redis直接获取数据,再结合Lua中Template组件,直接写入动态数据,渲染成页面,响应前端,一次请求响应过程结束.最终 ...
- Nginx Lua拓展模块操作Redis、Mysql
# Nginx的拓展模块 # ngx_lua模块 # 淘宝开发的ngx_lua模块通过lua解释器集成近Nginx,可以采用lua脚本实现业务逻辑,由于lua的紧凑.快速以及内建协程,所以在保证宝兵法 ...
- lua操作json,mysql,redis等
==========================example for lua json======================= local cjson = require("cj ...
- 高并发 Nginx+Lua OpenResty系列(9)——HTTP服务
此处我说的HTTP服务主要指如访问京东网站时我们看到的热门搜索.用户登录.实时价格.实时库存.服务支持.广告语等这种非Web页面,而是在Web页面中异步加载的相关数据.这些服务有个特点即访问量巨大.逻 ...
- nginx+lua+redis初体验
1.下载nginx.lua.redis nginx下载地址 wget http://nginx.org/download/nginx-1.8.0.tar.gz lua下载地址 wget http:/ ...
- Nginx + Lua + redis (一)(转)
使用 Lua 脚本语言操作 Redis. 由于大量的 Lua 代码写在 Nginx 中,会使配置文件显得很繁琐,所以这里使用 content_by_lua_file 来引入 Lua 脚本文件. 要使用 ...
随机推荐
- 100W数据,测试复合索引
复合索引不是那么容易被catch到的. 两个查询条件都是等于的时候,才会被catch到. mysql> select count(*) from tf_user_index where sex ...
- Linux 最好是禁用IPV6
看着不爽, 还容易出事. 编辑文件 – /etc/sysctl.conf $ sudo gedit /etc/sysctl.conf 在文件的最后加入下面的行. # IPv6 disabled net ...
- 一个故意消耗内存的java程序MemoryEater
公司提供的测试服务器是vmware的,号称给我6G, 物理内存事实上是按需分配的. 等到真正拿到6G物理内存,黄花菜都凉了. 看到下面的文章,觉得故意用java程序侵占6G内存, 然后把侵占到内存的释 ...
- java反射教程
什么是反射,为什么它是有用的,以及如何使用它? 1.什么是反射? “反射通常是JVM中运行的程序需要检测和修改运行时程序的行为的一种能力.”这个概念通常与内省(Introspection)混淆.以下是 ...
- vue/webpack的一些小技巧
都知道我比较懒,今天给大家分享的就是如何让自己省事. 一.vue修改打包后的结构(不知道怎么描述合理,看效果图) /config/index.js 默认的: 修改的:(顺手修改了打包后的文件名) 这样 ...
- Git创建仓库的方法(github翻译)
…通过命令行创建一个新的仓库 echo "# GitTest" >> README.md # 船舰一个说明文件,说明内容是 "# GitTest" ...
- ES6学习一 JS语言增强篇
一 背景 JavaScript经过二十来年年的发展,由最初简单的交互脚本语言,发展到今天的富客户端交互,后端服务器处理,跨平台(Native),以及小程序等等的应用.JS的角色越来越重要,处理场景越来 ...
- PHP网站自动化配置的实现
一直都在用yii2做项目,有在用自动化配置,但是没有自己去配置过.中午没事去看了下yii的初始化代码,发现都是php而已! yii2初始化项目代码 所以,我们做项目肯定是可以用php做的,于是我新建了 ...
- .net 应用程序 发布上线注意事项
生产环境发布时,对应的程序目录必须新建当日rar压缩包进行备份生产环境数据库发布时,必须创建存储过程的副本sql用于回滚,操作方式:F7调出对象资源管理器详细信息->选中所有存储过程->编 ...
- 总线设备驱动模型---platform篇
总线设备驱动模型----驱动篇 http://blog.chinaunix.net/uid-27664726-id-3334923.html http://blog.chinaunix.net/uid ...