Skip to content

Commit

Permalink
Skip WATCH if connection is already dirty (#1612)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
enjoy-binbin committed Jul 29, 2023
1 parent f3d3105 commit 758ce21
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/commands/cmd_txn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string>(args_.begin() + 1, args_.end()));
*output = redis::SimpleString("OK");
return Status::OK();
Expand Down

0 comments on commit 758ce21

Please sign in to comment.