Skip to content

Commit

Permalink
use a set to make sure no duplicate channels are added
Browse files Browse the repository at this point in the history
  • Loading branch information
a114j0y committed Aug 26, 2024
1 parent b512a9a commit 5c0a375
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions common/redispipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <string>
#include <queue>
#include <unordered_set>
#include <functional>
#include <chrono>
#include <iostream>
Expand Down Expand Up @@ -159,9 +160,11 @@ class RedisPipeline {

void addChannel(std::string channel)
{
m_luaPub +=
"redis.call('PUBLISH', '" + channel + "', 'G');";
if (m_channels.find(channel) != m_channels.end())
return;

m_channels.insert(channel);
m_luaPub += "redis.call('PUBLISH', '" + channel + "', 'G');";
m_shaPub = loadRedisScript(m_luaPub);
}

Expand All @@ -178,7 +181,8 @@ class RedisPipeline {

std::string m_luaPub;
std::string m_shaPub;
std::chrono::time_point<std::chrono::steady_clock> lastHeartBeat;
std::chrono::time_point<std::chrono::steady_clock> lastHeartBeat; // marks the timestamp of latest pipeline flush being invoked
std::unordered_set<std::string> m_channels;

void publish() {
if (m_shaPub == "") {
Expand Down

0 comments on commit 5c0a375

Please sign in to comment.