本文整理汇总了C++中Context::GetBlockContext方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::GetBlockContext方法的具体用法?C++ Context::GetBlockContext怎么用?C++ Context::GetBlockContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context::GetBlockContext方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ClearBlockKeys
void Ardb::ClearBlockKeys(Context& ctx)
{
if (NULL != ctx.block)
{
if (ctx.block->blocking_timer_task_id != -1)
{
ctx.client->GetService().GetTimer().Cancel(ctx.block->blocking_timer_task_id);
}
WatchKeySet::iterator it = ctx.GetBlockContext().keys.begin();
while (it != ctx.GetBlockContext().keys.end())
{
WriteLockGuard<SpinRWLock> guard(m_block_ctx_lock);
BlockContextTable::iterator fit = m_block_context_table.find(*it);
if (fit != m_block_context_table.end())
{
fit->second.erase(std::remove(fit->second.begin(), fit->second.end(), &ctx), fit->second.end());
if (fit->second.empty())
{
m_block_context_table.erase(fit);
}
}
}
ctx.ClearBlockContext();
}
}
示例2: AddBlockKey
void Ardb::AddBlockKey(Context& ctx, const std::string& key)
{
DBItemKey kk(ctx.currentDB, key);
ctx.GetBlockContext().keys.insert(kk);
WriteLockGuard<SpinRWLock> guard(m_block_ctx_lock);
m_block_context_table[kk].push_back(&ctx);
}
示例3: BRPopLPush
int Comms::BRPopLPush(Context& ctx, RedisCommandFrame& cmd)
{
uint32 timeout;
if (!string_touint32(cmd.GetArguments()[cmd.GetArguments().size() - 1], timeout))
{
fill_error_reply(ctx.reply, "timeout is not an integer or out of range");
return 0;
}
RPopLPush(ctx, cmd);
if (ctx.reply.type == REDIS_REPLY_NIL)
{
//block;
AddBlockKey(ctx, cmd.GetArguments()[0]);
ctx.GetBlockContext().lpop = false;
ctx.GetBlockContext().push_key = cmd.GetArguments()[1];
if (NULL != ctx.client)
{
ctx.client->DetachFD();
if (timeout > 0)
{
ctx.block->blocking_timer_task_id = ctx.client->GetService().GetTimer().ScheduleHeapTask(
new BlockListTimeout(&ctx), timeout, -1, SECONDS);
}
}
ctx.reply.type = 0;
}
return 0;
}
示例4: AddBlockKey
void Comms::AddBlockKey(Context& ctx, const std::string& keystr)
{
WatchKey key(ctx.currentDB, keystr);
WriteLockGuard<SpinRWLock> guard(m_block_ctx_lock);
ctx.GetBlockContext().keys.insert(key);
m_block_context_table[key].insert(&ctx);
}
示例5: WakeBlockedList
void Comms::WakeBlockedList(Context& ctx, const std::string& key)
{
std::string v;
int err =
ctx.GetBlockContext().lpop ?
m_kv_store->LPop(ctx.currentDB, key, v) : m_kv_store->RPop(ctx.currentDB, key, v);
if (0 == err && !v.empty())
{
if (ctx.GetBlockContext().push_key.empty())
{
RedisReply& r1 = ctx.reply.AddMember();
RedisReply& r2 = ctx.reply.AddMember();
fill_str_reply(r1, key);
fill_str_reply(r2, v);
if (!ctx.flags.no_wal)
{
RedisCommandFrame list_pop(ctx.GetBlockContext().lpop ? "lpop" : "rpop");
list_pop.AddArg(key);
m_repl.WriteWAL(ctx.currentDB, list_pop);
}
}
else
{
err = m_kv_store->RPush(ctx.currentDB, ctx.GetBlockContext().push_key, v);
if (err < 0)
{
ctx.GetBlockContext().lpop ?
m_kv_store->LPush(ctx.currentDB, key, v) : m_kv_store->RPush(ctx.currentDB, key, v);
FillErrorReply(ctx, err);
}
else
{
fill_str_reply(ctx.reply, v);
if (!ctx.flags.no_wal)
{
RedisCommandFrame rpoplpush("rpoplpush");
rpoplpush.AddArg(key);
m_repl.WriteWAL(ctx.currentDB, rpoplpush);
}
}
}
ctx.client->Write(ctx.reply);
ctx.client->AttachFD();
ClearBlockKeys(ctx);
}
}
示例6: BLPop
int Comms::BLPop(Context& ctx, RedisCommandFrame& cmd)
{
uint32 timeout;
if (!string_touint32(cmd.GetArguments()[cmd.GetArguments().size() - 1], timeout))
{
fill_error_reply(ctx.reply, "timeout is not an integer or out of range");
return 0;
}
bool lpop = cmd.GetType() == REDIS_CMD_BLPOP;
for (uint32 i = 0; i < cmd.GetArguments().size() - 1; i++)
{
std::string v;
int err =
lpop ? m_kv_store->LPop(ctx.currentDB, cmd.GetArguments()[i], v) : m_kv_store->RPop(ctx.currentDB,
cmd.GetArguments()[i], v);
if (0 == err && !v.empty())
{
RedisReply& r1 = ctx.reply.AddMember();
RedisReply& r2 = ctx.reply.AddMember();
fill_str_reply(r1, cmd.GetArguments()[i]);
fill_str_reply(r2, v);
FireKeyChangedEvent(ctx, ctx.currentDB, cmd.GetArguments()[i]);
RedisCommandFrame list_pop(lpop ? "lpop" : "rpop");
list_pop.AddArg(cmd.GetArguments()[i]);
RewriteClientCommand(ctx, list_pop);
return 0;
}
if (err != 0 && err != mmkv::ERR_ENTRY_NOT_EXIST && err != mmkv::ERR_DB_NOT_EXIST)
{
FillErrorReply(ctx, err);
return 0;
}
}
if (NULL != ctx.client)
{
ctx.client->DetachFD();
ctx.GetBlockContext().lpop = cmd.GetType() == REDIS_CMD_BLPOP;
if (timeout > 0)
{
ctx.block->blocking_timer_task_id = ctx.client->GetService().GetTimer().ScheduleHeapTask(
new BlockListTimeout(&ctx), timeout, -1, SECONDS);
}
}
for (uint32 i = 0; i < cmd.GetArguments().size() - 1; i++)
{
AddBlockKey(ctx, cmd.GetArguments()[i]);
}
return 0;
}