Ejemplo n.º 1
0
	int ArdbServer::Exec(ArdbConnContext& ctx, RedisCommandFrame& cmd)
	{
		if (ctx.fail_transc || !ctx.in_transaction)
		{
			ctx.reply.type = REDIS_REPLY_NIL;
		}
		else
		{
			RedisReply r;
			r.type = REDIS_REPLY_ARRAY;
			if (NULL != ctx.transaction_cmds)
			{
				for (uint32 i = 0; i < ctx.transaction_cmds->size(); i++)
				{
					RedisCommandFrame& cmd = ctx.transaction_cmds->at(i);
					DoRedisCommand(ctx,
					        FindRedisCommandHandlerSetting(cmd.GetCommand()),
					        cmd);
					r.elements.push_back(ctx.reply);
				}
			}
			ctx.reply = r;
		}
		ctx.in_transaction = false;
		DELETE(ctx.transaction_cmds);
		ClearWatchKeys(ctx);
		return 0;
	}
Ejemplo n.º 2
0
 int Ardb::Exec(Context& ctx, RedisCommandFrame& cmd)
 {
     if (!ctx.InTransc())
     {
         fill_error_reply(ctx.reply, "EXEC without MULTI");
         return 0;
     }
     if (ctx.GetTransc().abort)
     {
         ctx.reply.type = REDIS_REPLY_NIL;
         ctx.ClearTransc();
         return 0;
     }
     LockGuard<ThreadMutex> guard(g_transc_mutex); //only one transc allowed exec at the same time in multi threads
     RedisCommandFrameArray::iterator it = ctx.GetTransc().cached_cmds.begin();
     Context transc_ctx;
     transc_ctx.currentDB = ctx.currentDB;
     while (it != ctx.GetTransc().cached_cmds.end())
     {
         RedisReply& r = ctx.reply.AddMember();
         RedisCommandHandlerSetting* setting = FindRedisCommandHandlerSetting(*it);
         if(NULL != setting)
         {
             transc_ctx.reply.Clear();
             DoCall(transc_ctx, *setting, *it);
             r.Clone(transc_ctx.reply);
         }
         else
         {
             fill_error_reply(r, "unknown command '%s'", it->GetCommand().c_str());
         }
         it++;
     }
     ctx.currentDB = transc_ctx.currentDB;
     ctx.ClearTransc();
     UnwatchKeys(ctx);
     return 0;
 }