本文整理汇总了C++中Context::GetPubsub方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::GetPubsub方法的具体用法?C++ Context::GetPubsub怎么用?C++ Context::GetPubsub使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context::GetPubsub方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UnsubscribeChannel
int Ardb::UnsubscribeChannel(Context& ctx, const std::string& channel, bool notify)
{
ctx.GetPubsub().pubsub_channels.erase(channel);
WriteLockGuard<SpinRWLock> guard(m_pubsub_ctx_lock);
PubsubContextTable::iterator it = m_pubsub_channels.find(channel);
int ret = 0;
if (it != m_pubsub_channels.end())
{
it->second.erase(&ctx);
if (it->second.empty())
{
m_pubsub_channels.erase(it);
}
ret = 1;
}
if (notify && NULL != ctx.client)
{
RedisReply r;
RedisReply& r1 = r.AddMember();
RedisReply& r2 = r.AddMember();
RedisReply& r3 = r.AddMember();
fill_str_reply(r1, "unsubscribe");
fill_str_reply(r2, channel);
fill_int_reply(r3, ctx.GetPubsub().pubsub_channels.size() + ctx.GetPubsub().pubsub_patterns.size());
ctx.client->Write(r);
}
return ret;
}
示例2: UnsubscribeAll
int Ardb::UnsubscribeAll(Context& ctx, bool notify)
{
if(NULL == ctx.pubsub)
{
return 0;
}
StringSet tmp = ctx.GetPubsub().pubsub_channels;
StringSet::iterator it = tmp.begin();
int count = 0;
while (it != tmp.end())
{
count += UnsubscribeChannel(ctx, *it, notify);
it++;
}
if (notify && count == 0 && NULL != ctx.client)
{
RedisReply r;
RedisReply& r1 = r.AddMember();
RedisReply& r2 = r.AddMember();
RedisReply& r3 = r.AddMember();
fill_str_reply(r1, "unsubscribe");
r2.type = REDIS_REPLY_NIL;
fill_int_reply(r3, ctx.GetPubsub().pubsub_channels.size() + ctx.GetPubsub().pubsub_patterns.size());
ctx.client->Write(r);
}
return 0;
}
示例3: SubscribeChannel
int Ardb::SubscribeChannel(Context& ctx, const std::string& channel, bool notify)
{
ctx.GetPubsub().pubsub_channels.insert(channel);
{
WriteLockGuard<SpinRWLock> guard(m_pubsub_ctx_lock);
m_pubsub_channels[channel].insert(&ctx);
}
if (notify && NULL != ctx.client)
{
RedisReply r;
RedisReply& r1 = r.AddMember();
RedisReply& r2 = r.AddMember();
RedisReply& r3 = r.AddMember();
fill_str_reply(r1, "subscribe");
fill_str_reply(r2, channel);
fill_int_reply(r3, ctx.GetPubsub().pubsub_channels.size() + ctx.GetPubsub().pubsub_patterns.size());
ctx.client->Write(r);
}
return 0;
}