mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
batch mode in redis
This commit is contained in:
@@ -2,8 +2,10 @@ local skynet = require "skynet"
|
||||
local string = string
|
||||
local table = table
|
||||
local unpack = unpack
|
||||
local assert = assert
|
||||
|
||||
local redis_manager
|
||||
local batch = false
|
||||
|
||||
local redis = {}
|
||||
|
||||
@@ -12,21 +14,40 @@ local command = {}
|
||||
setmetatable(command, { __index = function(t,k)
|
||||
local cmd = string.upper(k)
|
||||
local f = function(self, ...)
|
||||
local err, result = skynet.call( self.__handle, "lua", cmd, ...)
|
||||
assert(err, result)
|
||||
return result
|
||||
if batch then
|
||||
skynet.send( self.__handle, "lua", cmd , ...)
|
||||
else
|
||||
local err, result = skynet.call( self.__handle, "lua", cmd, ...)
|
||||
assert(err, result)
|
||||
return result
|
||||
end
|
||||
end
|
||||
t[k] = f
|
||||
return f
|
||||
end})
|
||||
|
||||
function command:exists(key)
|
||||
assert(not batch, "exists can't used in batch mode")
|
||||
local result , exists = skynet.call( self.__handle, "lua" , "EXISTS", key)
|
||||
assert(result, exists)
|
||||
exists = exists ~= 0
|
||||
return exists
|
||||
end
|
||||
|
||||
function command:batch(mode)
|
||||
if mode == "end" then
|
||||
assert(batch, "Open batch mode first")
|
||||
batch = false
|
||||
local err, result = skynet.unpack(skynet.rawcall( self.__handle, "text", mode))
|
||||
assert(err, result)
|
||||
return result
|
||||
else
|
||||
assert(mode == "read" or mode == "write")
|
||||
batch = mode
|
||||
skynet.send( self.__handle, "text", mode)
|
||||
end
|
||||
end
|
||||
|
||||
local meta = {
|
||||
__index = command
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user