rdb.usp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!--#
  2. Test type 2: Single database query
  3. TechEmpower Web Framework Benchmarks
  4. -->
  5. <!--#declaration
  6. #include "world.h"
  7. static char buffer[128];
  8. static UREDISClient_Base* rc;
  9. #ifndef AS_cpoll_cppsp_DO
  10. static UValue* pvalue;
  11. #endif
  12. static void usp_fork_rdb()
  13. {
  14. U_TRACE(5, "::usp_fork_rdb()")
  15. U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);
  16. if (rc->connect() == false)
  17. {
  18. U_WARNING("usp_fork_rdb(): %V", rc->UClient_Base::getResponse().rep);
  19. return;
  20. }
  21. u__memcpy(buffer, "world:", U_CONSTANT_SIZE("world:"), __PRETTY_FUNCTION__);
  22. #ifndef AS_cpoll_cppsp_DO
  23. U_NEW(UValue, pvalue, UValue(OBJECT_VALUE));
  24. #endif
  25. }
  26. #ifdef DEBUG
  27. static void usp_end_rdb()
  28. {
  29. U_TRACE(5, "::usp_end_rdb()")
  30. delete rc;
  31. #ifndef AS_cpoll_cppsp_DO
  32. if (pvalue) delete pvalue;
  33. #endif
  34. }
  35. #endif
  36. -->
  37. <!--#header
  38. Content-Type: application/json
  39. -->
  40. <!--#code
  41. uint32_t id;
  42. (void) rc->get(buffer, 6+u_num2str32(buffer+6, id = u_get_num_random(10000-1)));
  43. #ifdef AS_cpoll_cppsp_DO
  44. USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, rc->vitem[0].rep);
  45. #else
  46. UStringRep* rep = rc->vitem[0].rep;
  47. World world(id, u_strtoul(rep->data(), rep->end()));
  48. USP_JSON_stringify(*pvalue, World, world);
  49. pvalue->clear();
  50. #endif
  51. -->