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的更多相关文章

  1. 使用Nginx Lua实现redis高性能http接口

    使用Nginx Lua实现redis高性能http接口 时间 -- :: 峰云就她了 原文 http://xiaorui.cc/2015/01/27/使用nginx-lua实现redis高性能http ...

  2. nginx lua mysql redis设置

    最近公司网站改版,程序和数据库全部用新版,旧版的数据要导入,旧网站的30万条数据url要全部重定向到新版网站,正好前段时间在学习nginx+lua+mysql+memcache(redis),找资料真 ...

  3. lua 操作redis

    Redis在2.6推出了脚本功能,允许开发者使用Lua语言编写脚本传到Redis中执行.使用脚本的好处如下: 1.减少网络开销:本来5次网络请求的操作,可以用一个请求完成,原先5次请求的逻辑放在red ...

  4. Nginx+Lua+MySQL/Redis实现高性能动态网页展现

    Nginx结合Lua脚本,直接绕过Tomcat应用服务器,连接MySQL/Redis直接获取数据,再结合Lua中Template组件,直接写入动态数据,渲染成页面,响应前端,一次请求响应过程结束.最终 ...

  5. Nginx Lua拓展模块操作Redis、Mysql

    # Nginx的拓展模块 # ngx_lua模块 # 淘宝开发的ngx_lua模块通过lua解释器集成近Nginx,可以采用lua脚本实现业务逻辑,由于lua的紧凑.快速以及内建协程,所以在保证宝兵法 ...

  6. lua操作json,mysql,redis等

    ==========================example for lua json======================= local cjson = require("cj ...

  7. 高并发 Nginx+Lua OpenResty系列(9)——HTTP服务

    此处我说的HTTP服务主要指如访问京东网站时我们看到的热门搜索.用户登录.实时价格.实时库存.服务支持.广告语等这种非Web页面,而是在Web页面中异步加载的相关数据.这些服务有个特点即访问量巨大.逻 ...

  8. nginx+lua+redis初体验

    1.下载nginx.lua.redis nginx下载地址 wget  http://nginx.org/download/nginx-1.8.0.tar.gz lua下载地址 wget http:/ ...

  9. Nginx + Lua + redis (一)(转)

    使用 Lua 脚本语言操作 Redis. 由于大量的 Lua 代码写在 Nginx 中,会使配置文件显得很繁琐,所以这里使用 content_by_lua_file 来引入 Lua 脚本文件. 要使用 ...

随机推荐

  1. UI 交互

    动效设计 亮色优缺点 排版 原型图交互说明

  2. 解决"No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android"错误

    今天安装了Android Studio 3.2,打开一个旧工程,编译提示"No toolchains found in the NDK toolchains folder for ABI w ...

  3. Java网络编程学习A轮_05_Socket编程

    示例代码: https://github.com/gordonklg/study,socket module A. Socket 编程简单例子 最简单的 Socket 编程是通过回车/换行符,整行读取 ...

  4. angular的 表单

    一般来讲表单可能遇到的问题:1.如何数据绑定.2.验证表单.3.显示出错信息.4.整个form的验证.5.避免提交没有验证通过的表单.6.防止多系提交. input属性:nameng-modelng- ...

  5. redis集群登陆

    如何登陆redis集群 redis-cli -h 10.12.4.45 -p 7000 -c -a alkdsjf134rj01 ip:10.12.4.45 集群中的一个点 -c 以集群方式登陆.cl ...

  6. winform学习目录

    Winform混合式开发框架的特点总结 伍华聪 2016-02-26 10:47 阅读:1966 评论:2     代码生成工具Database2Sharp中增加视图的代码生成以及主从表界面生成功能  ...

  7. ISE创建Microblaze软核(三)

    第七步 进入SDK开发环境 编译完成后弹出如下对话框,选择SDK的工作目录.在MicroblazeTutor中创建一个Workspace文件夹,并选择该文件夹为SDK的工作目录. 进入SDK主界面. ...

  8. windows下查看端口是否被占,以及端口被哪个程序占用

    如何查看端口被是否被占用 在 “ 命令提示符 ” 中输入 “netstat -an”, 即可显示本机所有开放端口.下表是具体的说明. 数据列 说明 propo 指连接使用的协议名称 local add ...

  9. Git 学习之 Git Basics

    最近在用git,但git学习曲线实在是有点高. 好在找到一个文档 https://www.atlassian.com/git/tutorial/,以下就是学习笔记吧! git init git ini ...

  10. Tensorflow 模型文件结构、模型中Tensor查看

    tensorflow训练后保存的模型主要包含两部分,一是网络结构的定义(网络图),二是网络结构里的参数值. 1.  .meta文件 .meta 文件以 "protocol buffer&qu ...