From 922ce27a77367f095107220737ef2eb9c097a014 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Thu, 4 Jun 2020 14:25:51 +0800 Subject: [PATCH] pika 判断 --- src/shared/redisproxy.lua | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 5 deletions(-) diff --git a/src/shared/redisproxy.lua b/src/shared/redisproxy.lua index 97ad4d8..7c60913 100644 --- a/src/shared/redisproxy.lua +++ b/src/shared/redisproxy.lua @@ -5,6 +5,10 @@ local table_insert = table.insert local redisproxy = {} + +local isUsePika = false + + setmetatable(redisproxy, { __index = function(t, k) local cmd = string.upper(k) local f = function (self, ...) @@ -38,14 +42,61 @@ function redisproxy:runScripts(name, ...) end local meta = {__index = function (tab, name) return function (_, ...) tab[#tab+1]={name, ...} end end} -function redisproxy:pipelining(block) - local ops = setmetatable({{"multi"}}, meta) +function redisproxy:pipelining(block, transaction) + if transaction == nil then transaction = true end -- 默认具有事务性 + if isUsePika then transaction = false end + + local ops = setmetatable({}, meta) + if transaction then + ops[#ops+1]={"multi"} + end block(ops) - if #ops == 1 then return end - ops[#ops+1]={"exec"} - return self:pipeline(ops) + if transaction then + if #ops == 1 then return end + ops[#ops+1]={"exec"} + else + if #ops == 0 then return end + end + return self:pipeline(ops, transaction) +end + +if isUsePika then + +function redisproxy:insertEmail(params) + local roleId = params.roleId + local emailId = params.emailId + local createtime = params.createtime or skynet.timex() + local contentPms = params.contentPms or {} + local rewardPms = params.rewardPms or {} + local title = params.title or "" + local stitle = params.stitle or "" + local content = params.content or "" + local attachments = params.attachments or "" + + local id = self:HINCRBY(string.format("role:%d:autoincr", roleId), "email", 1) + self:LPUSH(string.format("role:%d:emailIds", roleId), id) + local deleteIds = self:LRANGE(string.format("role:%d:emailIds", roleId), EMAIL_LIMIT, -1) + self:pipelining(function(red) + for _, deleteId in ipairs(deleteIds) do + red:DEL(string.format("email:%d:%d", roleId, deleteId)) + end + red:LTRIM(string.format("role:%d:emailIds", roleId), 0, EMAIL_LIMIT - 1) + red:HMSET(string.format("email:%d:%d", roleId, id), + "id", tostring(id), + "emailId", emailId, + "status", "0", + "createtime", createtime, + "contentPms", MsgPack.pack(contentPms), + "rewardPms", MsgPack.pack(rewardPms), + "title", title, + "stitle", stitle, + "content", content, + "attachments", attachments) + end) end +else + function redisproxy:insertEmail(params) local pms = { roleId = params.roleId, @@ -64,4 +115,7 @@ function redisproxy:insertEmail(params) return true end + +end + return redisproxy \ No newline at end of file -- libgit2 0.21.2