Lua 的 IO 框架 Luajit IO

码农软件 · 软件分类 · 高性能网络开发库 · 2019-09-01 07:59:42
  • 授权协议: BSD
  • 开发语言: Lua
  • 操作系统: 跨平台
  • 软件首页: http://luajit.io/

软件介绍

Luajit IO 是一个纯 Lua 的 IO 框架,提供 C 的高效率,简单但强大的设计,得益于 luajit 这个 JIT 引擎。可用来开发 TCP/UDP 服务器程序。

下面是连接 redis 的示例代码:

local ffi = require"ffi"
local null = ffi.new("void*")
local redis = require "resty.redis"

local function test_redis(req, rsp)
	local red = redis:new()

	-- red:set_timeout(1000) -- 1 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", 6379)
	if not ok then
		rsp:say("failed to connect: ", err)
		return
	end

	ok, err = red:set("dog", "an animal")
	if not ok then
		rsp:say("failed to set dog: ", err)
		return
	end

	rsp:say("set result: ", ok)

	local res, err = red:get("dog")
	if not res then
		rsp:say("failed to get dog: ", err)
		return
	end

	if res == null then
		rsp:say("dog not found.")
		return
	end

	rsp: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
		rsp:say("failed to commit the pipelined requests: ", err)
		return
	end

	for i, res in ipairs(results) do
		if type(res) == "table" then
			if not res[1] then
				rsp:say("failed to run command ", i, ": ", res[2])
			else
				-- process the table value
			end
		else
			-- process the scalar value
		end
	end

	-- put it into the connection pool of size 100,
	-- with 10 seconds max idle time
	local ok, err = red:set_keepalive(10000, 100)
	if not ok then
		rsp:say("failed to set keepalive: ", err)
		return
	end

	-- or just close the connection right away:
	-- local ok, err = red:close()
	-- if not ok then
	--     rsp:say("failed to close: ", err)
	--     return
	-- end
end

return test_redis

本文地址:https://codercto.com/soft/d/13620.html

别怕,Excel VBA其实很简单(第2版)

别怕,Excel VBA其实很简单(第2版)

Excel Home / 北京大学出版社 / 2016-7 / 59.00元

对于大部分没有编程基础的职场人士来说,在学习VBA时往往会有很大的畏难情绪。本书正是针对这样的人群,用浅显易懂的语言和生动形象的比喻,并配合大量插画,对Excel中看似复杂的概念和代码,从简单的宏录制、VBA编程环境和基础语法的介绍,到常用对象的操作与控制、执行程序的自动开关—对象的事件、设计自定义的操作界面、调试与优化编写的代码,都进行了形象的介绍。 本书适合那些希望提高工作效率的职场人士......一起来看看 《别怕,Excel VBA其实很简单(第2版)》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码

MD5 加密
MD5 加密

MD5 加密工具