redis执行命令并返回浏览器
该示例演示使用Redis连接池,及Redis执行命令与获取返回数据。local cjson = require("cjson")
local response = require("fastweb.response")
local request = require("fastweb.request")
local pool = require("redis.pool").new()
local function reply(code,msg,data)
response.header("Content-Type","application/json")
response.send(cjson.encode({
code = code,
msg = msg,
data = data
}))
end
-- 置连接池信息
pool:start("127.0.0.1",6379,"123456.",1)
-- 获取连接
local redis = pool:get()
-- 执行命令
local result = redis:command(request.param("command"))
-- 获取返回信息
reply(200,"OK",{reply=result})注意:需要安装redis扩展
页:
[1]