From 758ce2192a5a9d3bd8bc4dbd8bd8ce9475d4df66 Mon Sep 17 00:00:00 2001 From: Binbin Date: Sat, 29 Jul 2023 14:27:43 +0800 Subject: [PATCH] Skip WATCH if connection is already dirty (#1612) If a conn is already marked as watched_keys_modified, we can skip the watch. It is a cleanup and in some situations it may save us some memory and performance gains. --- src/commands/cmd_txn.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/commands/cmd_txn.cc b/src/commands/cmd_txn.cc index 3138c364702..b6c94c06a67 100644 --- a/src/commands/cmd_txn.cc +++ b/src/commands/cmd_txn.cc @@ -98,6 +98,12 @@ class CommandWatch : public Commander { return {Status::RedisExecErr, "WATCH inside MULTI is not allowed"}; } + // If a conn is already marked as watched_keys_modified, we can skip the watch. + if (svr->IsWatchedKeysModified(conn)) { + *output = redis::SimpleString("OK"); + return Status::OK(); + } + svr->WatchKey(conn, std::vector(args_.begin() + 1, args_.end())); *output = redis::SimpleString("OK"); return Status::OK();