From bdac40532463faad06ea25e4121230684025a8aa Mon Sep 17 00:00:00 2001 From: mk Date: Tue, 14 Oct 2025 21:30:09 +0800 Subject: [PATCH] Update: use pipeline for ASKING command in redis cluster (#2097) - ensure ASKING and command execute sequentially and consecutively - save one RTT --- lualib/skynet/db/redis/cluster.lua | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lualib/skynet/db/redis/cluster.lua b/lualib/skynet/db/redis/cluster.lua index e526fe4d..355b3798 100644 --- a/lualib/skynet/db/redis/cluster.lua +++ b/lualib/skynet/db/redis/cluster.lua @@ -344,15 +344,24 @@ function rediscluster:call(...) else conn = self:get_connection_by_slot(slot) end - local result = {pcall(function () - -- TODO: use pipelining to send asking and save a rtt. - if asking then - conn:asking() - end + + local result + if asking then + -- use pipeline + -- ensure ASKING and command execute sequentially and consecutively + -- save one RTT + local cmd_list = { + { "asking" }, + { ... }, + } asking = false + local func = conn["pipeline"] + result = { pcall(func, conn, cmd_list) } + else local func = conn[cmd] - return func(conn,table.unpack(argv,2)) - end)} + result = { pcall(func, conn, table.unpack(argv, 2)) } + end + local ok = result[1] if not ok then err = table.unpack(result,2)