LCOV - code coverage report
Current view: top level - src - utils_memcached.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 12 12 100.0 %
Date: 2025-11-03 22:25:15 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #ifndef SOCIAL_NETWORK_MICROSERVICES_SRC_UTILS_MEMCACHED_H_
       2             : #define SOCIAL_NETWORK_MICROSERVICES_SRC_UTILS_MEMCACHED_H_
       3             : 
       4             : #include <libmemcached/memcached.h>
       5             : #include <libmemcached/util.h>
       6             : 
       7             : namespace social_network {
       8             : 
       9           1 : memcached_pool_st *init_memcached_client_pool(
      10             :     const json &config_json,
      11             :     const std::string &service_name,
      12             :     uint32_t min_size,
      13             :     uint32_t max_size
      14             : ) {
      15           2 :   std::string addr = config_json[service_name + "-memcached"]["addr"];
      16           1 :   int port = config_json[service_name + "-memcached"]["port"];
      17           1 :   int use_binary_protocol = config_json[service_name + "-memcached"]["binary_protocol"];
      18           2 :   std::string config_str = "--SERVER=" + addr + ":" + std::to_string(port);
      19           1 :   auto memcached_client = memcached(config_str.c_str(), config_str.length());
      20           1 :   memcached_behavior_set(memcached_client, MEMCACHED_BEHAVIOR_NO_BLOCK, 1);
      21           1 :   memcached_behavior_set(memcached_client, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
      22           1 :   if (use_binary_protocol == 1) {
      23           1 :     memcached_behavior_set(memcached_client, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
      24             :   }
      25             : 
      26             :   auto memcached_client_pool =
      27           1 :       memcached_pool_create(memcached_client, min_size, max_size);
      28           2 :   return memcached_client_pool;
      29             : }
      30             : 
      31             : } // namespace social_network
      32             : 
      33             : #endif //SOCIAL_NETWORK_MICROSERVICES_SRC_UTILS_MEMCACHED_H_

Generated by: LCOV version 1.12