<!--#
Test type 5: Database updates
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
#include "world.h"

static char buffer[8192];
static UREDISClient_Base* rc;
static UVector<World*>* pvworld;

static void usp_fork_rupdate()
{
   U_TRACE(5, "::usp_fork_rupdate()")

   U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);

   if (rc->connect() == false)
      {
      U_WARNING("usp_fork_rupdate(): %V", rc->UClient_Base::getResponse().rep);

      delete rc;
             rc = U_NULLPTR;

      return;
      }

   U_NEW(UVector<World*>, pvworld, UVector<World*>(500));
}

#ifdef DEBUG
static void usp_end_rupdate()
{
   U_TRACE(5, "::usp_end_rupdate()")

   if (pvworld)
      {
      delete rc;
      delete pvworld;
      }
}
#endif
-->
<!--#header
Content-Type: application/json
-->
<!--#code
World* pworld;
char* pbuffer = buffer;
int i, num_queries = UHTTP::getFormFirstNumericValue(1, 500);

(void) UClientImage_Base::wbuffer->reserve(36U * num_queries);

#ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR('[');
#endif

for (i = 0; i < num_queries; ++i)
   {
   U_NEW(World, pworld, World);

   pvworld->push_back(pworld);

   u_put_unalignedp64(pbuffer, U_MULTICHAR_CONSTANT64(' ','w','o','r','l','d',':','\0'));

   pbuffer = u_num2str32(pworld->id = u_get_num_random(10000-1), pbuffer+7);
   }

(void) rc->mget(buffer, pbuffer-buffer);

i = 0;
pbuffer = buffer;

while (true)
   {
   pworld = pvworld->at(i);

   u_put_unalignedp64(pbuffer, U_MULTICHAR_CONSTANT64(' ','w','o','r','l','d',':','\0'));

   pbuffer = u_num2str32(pworld->id, pbuffer+7);
  *pbuffer = ' ';
   pbuffer = u_num2str32(pworld->randomNumber = u_get_num_random(10000-1), pbuffer+1);

#ifdef AS_cpoll_cppsp_DO
   USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", pworld->id, pworld->randomNumber);
#endif

   if (++i == num_queries) break;

#ifdef AS_cpoll_cppsp_DO
   USP_PUTS_CHAR(',');
#endif
   }

(void) rc->mset(buffer, pbuffer-buffer);

#ifdef AS_cpoll_cppsp_DO
USP_PUTS_CHAR(']');
#else
USP_OBJ_JSON_stringify(*pvworld);
#endif
pvworld->clear();
-->
