update
This commit is contained in:
@@ -33,15 +33,21 @@ set(CMAKE_INSTALL_ALWAYS_COPY TRUE)
|
||||
|
||||
set(YLIB ${CMAKE_INSTALL_PREFIX}/../ylib)
|
||||
set(FASTWEB ${CMAKE_INSTALL_PREFIX}/../fastweb)
|
||||
|
||||
# 包含路径
|
||||
include_directories(
|
||||
${YLIB}/include
|
||||
${FASTWEB}/include
|
||||
${FASTWEB}/include/lua
|
||||
D:/3rdparty/hiredis
|
||||
|
||||
)
|
||||
if(MSVC)
|
||||
include_directories(
|
||||
${YLIB}/include
|
||||
${FASTWEB}/include
|
||||
${FASTWEB}/include/lua
|
||||
)
|
||||
add_definitions(/bigobj)
|
||||
else()
|
||||
include_directories(
|
||||
/usr/local/include/ylib
|
||||
/usr/local/include/fastweb
|
||||
/usr/local/include)
|
||||
add_definitions(-DfPIC)
|
||||
endif()
|
||||
|
||||
# 添加共享库
|
||||
add_library(${MODULE_NAME} SHARED ${HEADER_FILES} ${SOURCE_FILES})
|
||||
@@ -66,8 +72,9 @@ else()
|
||||
target_link_libraries(${MODULE_NAME}
|
||||
ylib
|
||||
crypto
|
||||
lua5.3
|
||||
lua
|
||||
pthread
|
||||
hiredis
|
||||
)
|
||||
|
||||
endif()
|
||||
|
||||
11
build.sh
Executable file
11
build.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
sudo apt-get install libhiredis-dev -y
|
||||
mkdir target -p
|
||||
mkdir build -p
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
cp -f libredis.so ../target
|
||||
@@ -2,7 +2,11 @@
|
||||
#include "base/define.h"
|
||||
#include "util/queue.hpp"
|
||||
#include "sol/sol.hpp"
|
||||
#include "hiredis.h"
|
||||
#ifdef _WIN32
|
||||
#include "redis.h"
|
||||
#else
|
||||
#include <hiredis/hiredis.h>
|
||||
#endif
|
||||
#include "basemodule.h"
|
||||
namespace module
|
||||
{
|
||||
|
||||
24
target/redis/conn.lua
Normal file
24
target/redis/conn.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
-- redis_conn.lua
|
||||
local redis_conn = {}
|
||||
redis_conn.__index = redis_conn
|
||||
|
||||
--[[
|
||||
创建一个新的 fw_redis_conn 对象
|
||||
@return 返回一个新的 fw_redis_conn 对象
|
||||
]]
|
||||
function redis_conn.new(__module)
|
||||
local instance = setmetatable({}, redis_conn)
|
||||
instance.module = __module
|
||||
return instance
|
||||
end
|
||||
|
||||
--[[
|
||||
执行 Redis 命令
|
||||
@param cmd Redis 命令字符串
|
||||
@return 返回命令执行结果
|
||||
]]
|
||||
function redis_conn:command(cmd)
|
||||
return self.module:command(cmd)
|
||||
end
|
||||
|
||||
return redis_conn
|
||||
50
target/redis/pool.lua
Normal file
50
target/redis/pool.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
local conn = require("redis.conn")
|
||||
|
||||
local redis_pool = {}
|
||||
redis_pool.__index = redis_pool
|
||||
|
||||
--[[
|
||||
创建一个新的 fw_redis_pool 对象
|
||||
@return 返回一个新的 fw_redis_pool 对象
|
||||
]]
|
||||
function redis_pool.new()
|
||||
local instance = setmetatable({}, redis_pool)
|
||||
instance.module = fw_redis_pool.new()
|
||||
return instance
|
||||
end
|
||||
|
||||
--[[
|
||||
启动 Redis 连接池
|
||||
@param address 地址
|
||||
@param port 端口号
|
||||
@param password 密码
|
||||
@param max_size 最大连接数
|
||||
]]
|
||||
function redis_pool:start(address, port, password, max_size)
|
||||
self.module:start(address, port, password, max_size)
|
||||
end
|
||||
|
||||
--[[
|
||||
关闭 Redis 连接池
|
||||
]]
|
||||
function redis_pool:close()
|
||||
self.module:close()
|
||||
end
|
||||
|
||||
--[[
|
||||
获取 Redis 连接
|
||||
@return 返回一个 redis 连接对象
|
||||
]]
|
||||
function redis_pool:get()
|
||||
return conn.new(self.module:get())
|
||||
end
|
||||
|
||||
--[[
|
||||
获取弹出连接数
|
||||
@return 返回弹出连接数
|
||||
]]
|
||||
function redis_pool:pop_size()
|
||||
return self.module:pop_size()
|
||||
end
|
||||
|
||||
return redis_pool
|
||||
Reference in New Issue
Block a user