mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 03:53:09 +00:00
reds pipeline v2(support function as pipeline params)
fix a bug & add function as pipeline params
This commit is contained in:
72
test/testpipeline.lua
Normal file
72
test/testpipeline.lua
Normal file
@@ -0,0 +1,72 @@
|
||||
local skynet = require "skynet"
|
||||
local redis = require "redis"
|
||||
|
||||
local conf = {
|
||||
host = "127.0.0.1",
|
||||
port = 6379,
|
||||
db = 0
|
||||
}
|
||||
|
||||
local function read_table(t)
|
||||
local result = { }
|
||||
for i = 1, #t, 2 do result[t[i]] = t[i + 1] end
|
||||
return result
|
||||
end
|
||||
|
||||
skynet.start(function()
|
||||
local db = redis.connect(conf)
|
||||
|
||||
db.pipelining = function (self, block)
|
||||
local ops = {}
|
||||
|
||||
block(setmetatable({}, {
|
||||
__index = function (_, name)
|
||||
return function (_, ...)
|
||||
table.insert(ops, {name, ...})
|
||||
end
|
||||
end
|
||||
}))
|
||||
|
||||
return self:pipeline(ops)
|
||||
end
|
||||
|
||||
do
|
||||
print("test function")
|
||||
local ret = db:pipelining(function (red)
|
||||
red:hincrby("hello", 1, 1)
|
||||
red:del("hello")
|
||||
red:hmset("hello", 1, 1, 2, 2, 3, 3)
|
||||
red:hgetall("hello")
|
||||
end)
|
||||
|
||||
print(ret[1].out)
|
||||
print(ret[2].out)
|
||||
print(ret[3].out)
|
||||
|
||||
for k, v in pairs(read_table(ret[4].out)) do
|
||||
print(k, v)
|
||||
end
|
||||
end
|
||||
|
||||
do
|
||||
print("test table")
|
||||
local ret = db:pipeline {
|
||||
{"hincrby", "hello", 1, 1},
|
||||
{"del", "hello"},
|
||||
{"hmset", "hello", 1, 1, 2, 2, 3, 3},
|
||||
{"hgetall", "hello"},
|
||||
}
|
||||
|
||||
print(ret[1].out)
|
||||
print(ret[2].out)
|
||||
print(ret[3].out)
|
||||
|
||||
for k, v in pairs(read_table(ret[4].out)) do
|
||||
print(k, v)
|
||||
end
|
||||
end
|
||||
|
||||
db:disconnect()
|
||||
skynet.exit()
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user