### Quick Start Build and Install Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-configure.md Execute these commands for a quick build and installation of libpqxx. ```shell ./configure make sudo make install ``` -------------------------------- ### Quick Start CMake Build Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-cmake.md Run these commands from the root of the libpqxx source tree to quickly configure, build, and install the library. ```shell cmake --build . cmake --install . ``` -------------------------------- ### Setup Build Tools and Dependencies Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/building-with-vs2019.md Installs necessary build tools and dependencies using the vcpkg package manager. This is a one-time, time-consuming step. ```console cd opentelemetry-cpp tools\setup-buildtools.cmd ``` -------------------------------- ### Library Target Setup Macro Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/src/CMakeLists.txt Sets up include directories, links libraries, and handles installation for a target. Includes Windows-specific library linking. ```cmake macro(library_target_setup tgt) target_include_directories(${tgt} PUBLIC $ $ $ PRIVATE ${PostgreSQL_INCLUDE_DIRS} ) target_link_libraries(${tgt} PRIVATE ${PostgreSQL_LIBRARIES}) if(WIN32) target_link_libraries(${tgt} PUBLIC wsock32 ws2_32) endif() install(TARGETS ${tgt} EXPORT libpqxx-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ) get_target_property(name ${tgt} NAME) get_target_property(output_name ${tgt} OUTPUT_NAME) if(NOT CMAKE_HOST_WIN32) # Create library symlink get_target_property(target_type ${tgt} TYPE) if(target_type STREQUAL "SHARED_LIBRARY") set(library_prefix ${CMAKE_SHARED_LIBRARY_PREFIX}) set(library_suffix ${CMAKE_SHARED_LIBRARY_SUFFIX}) elseif(target_type STREQUAL "STATIC_LIBRARY") set(library_prefix ${CMAKE_STATIC_LIBRARY_PREFIX}) set(library_suffix ${CMAKE_STATIC_LIBRARY_SUFFIX}) endif() list(APPEND noop_command "${CMAKE_COMMAND}" "-E" "true") list(APPEND create_symlink_command "${CMAKE_COMMAND}" "-E" "create_symlink" "${library_prefix}${output_name}${library_suffix}" "${library_prefix}${name}${library_suffix}") # `add_custom_command()` does nothing if the `OUTPUT_NAME` and `NAME` # properties are equal, otherwise it creates library symlink. add_custom_command(TARGET ${tgt} POST_BUILD COMMAND "$,${noop_command},${create_symlink_command}>" VERBATIM COMMAND_EXPAND_LISTS ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${library_prefix}${name}${library_suffix} DESTINATION ${CMAKE_INSTALL_LIBDIR} ) endif() endmacro() ``` -------------------------------- ### Build Example with Bazel Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/CONTRIBUTING.md Use this command to build a specific example from the examples folder using Bazel. Replace placeholders with your example's directory and binary name. ```bash bazel build //examples/: ``` -------------------------------- ### Install libpqxx Library Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-configure.md Run this command to install the libpqxx library after configuration. Ensure you have the necessary write privileges for the installation location. ```shell make install ``` -------------------------------- ### Configure and Install pkg-config File Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/src/CMakeLists.txt Configures the libpqxx.pc file using a template and installs it to the pkgconfig directory. ```cmake # install pkg-config file set(prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${prefix}) set(libdir " ${prefix}/${CMAKE_INSTALL_LIBDIR}") set(includedir " ${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") set(VERSION ${PROJECT_VERSION}) configure_file(${PROJECT_SOURCE_DIR}/libpqxx.pc.in ${PROJECT_BINARY_DIR}/libpqxx.pc) install(FILES ${PROJECT_BINARY_DIR}/libpqxx.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) ``` -------------------------------- ### Build and Run Simple Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/CONTRIBUTING.md Specific commands to build and run the 'simple' example, demonstrating the general build and run process. ```bash bazel build //examples/simple:example_simple ``` ```bash bazel-bin/examples/simple/example_simple ``` -------------------------------- ### Install libpqxx using CMake Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-cmake.md Install the built libpqxx library and headers to the system's default location. This command uses CMake's installation capabilities. ```shell cmake --install $BUILD ``` -------------------------------- ### Install libpqxx to a custom prefix Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-cmake.md Install the built libpqxx library and headers to a specific destination directory. Use the --prefix option to specify a custom installation path. ```shell cmake --install $BUILD --prefix $DEST ``` -------------------------------- ### Run Prometheus Exporter Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/prometheus/README.md Execute the OpenTelemetry Prometheus exporter example using Bazel. This command starts the application that exports metrics to a default endpoint. ```sh bazel run //examples/prometheus:prometheus_example ``` -------------------------------- ### Build and Start Test Server Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/ext/test/w3c_tracecontext_http_test_server/README.md Execute the test server binary to start listening for HTTP requests. A custom port can be specified as an argument. ```sh ./w3c_tracecontext_http_test_server Listening to http://localhost:30000/test ``` ```sh ./w3c_tracecontext_http_test_server 31339 Listening to http://localhost:31339/test ``` -------------------------------- ### Run Example with Bazel Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/CONTRIBUTING.md Execute the compiled example binary to observe telemetry output. Ensure you are in the root directory of the opentelemetry-cpp project. ```bash bazel-bin/examples// ``` -------------------------------- ### Configure Zipkin Trace Exporter Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/zipkin/CMakeLists.txt Configures an executable named 'example_zipkin' and links it with a common library and the OpenTelemetry Zipkin trace exporter. This setup is necessary for sending traces to a Zipkin collector. ```cmake add_executable(example_zipkin main.cc) target_link_libraries( example_zipkin PRIVATE common_foo_library opentelemetry-cpp::zipkin_trace_exporter) ``` -------------------------------- ### Install hiredis from source Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Install hiredis from its source code. Ensure you are installing only one version to avoid conflicts. ```bash git clone https://github.com/redis/hiredis.git cd hiredis make make install ``` -------------------------------- ### Basic Executable Example with Prometheus-cpp-lite Core Source: https://github.com/zerotier/zerotierone/blob/dev/ext/prometheus-cpp-lite-1.0/examples/CMakeLists.txt This snippet shows how to set up a basic executable that links against the prometheus-cpp-lite core library. Use this as a starting point for applications that need core Prometheus metric functionality. ```cmake add_executable (original_example "original_example.cpp" ) target_link_libraries(original_example prometheus-cpp-lite-core) ``` ```cmake add_executable (modern_example "modern_example.cpp" ) target_link_libraries(modern_example prometheus-cpp-lite-core) ``` ```cmake add_executable (use_counters_in_class_example "use_counters_in_class_example.cpp" ) target_link_libraries(use_counters_in_class_example prometheus-cpp-lite-core) ``` ```cmake add_executable (use_gauge_in_class_example "use_gauge_in_class_example.cpp" ) target_link_libraries(use_gauge_in_class_example prometheus-cpp-lite-core) ``` ```cmake add_executable (use_benchmark_in_class_example "use_benchmark_in_class_example.cpp" ) target_link_libraries(use_benchmark_in_class_example prometheus-cpp-lite-core) ``` ```cmake add_executable (save_to_file_example "save_to_file_example.cpp" ) target_link_libraries(save_to_file_example prometheus-cpp-lite-core) ``` ```cmake add_executable (push_to_server_example "push_to_server_example.cpp" ) target_link_libraries(push_to_server_example prometheus-cpp-lite-core) ``` ```cmake add_executable (gateway_example "gateway_example.cpp" ) target_link_libraries(gateway_example prometheus-cpp-lite-core) ``` -------------------------------- ### Install ZeroTier on Linux Source: https://context7.com/zerotier/zerotierone/llms.txt Install the ZeroTier service on a Linux system after building from source. Requires superuser privileges. ```bash sudo make install ``` -------------------------------- ### Configure Common Examples Directory and Add Subdirectories Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/common/CMakeLists.txt Sets the common examples directory and includes subdirectories for different example libraries. This is a standard CMake configuration for managing example projects. ```cmake set(EXAMPLES_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(foo_library) add_subdirectory(logs_foo_library) add_subdirectory(metrics_foo_library) ``` -------------------------------- ### Example Bazel Test Command Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/google-test.md A consolidated command to build and run the `tracer_provider_test` example using Bazel. ```console bazel test //sdk/test/trace:tracer_provider_test ``` -------------------------------- ### Install FreeBSD Dependencies Source: https://context7.com/zerotier/zerotierone/llms.txt Install necessary dependencies for building ZeroTier on FreeBSD systems before proceeding with the build. ```bash pkg install binutils gmake ``` -------------------------------- ### Start ZeroTier Service Source: https://context7.com/zerotier/zerotierone/llms.txt Start the ZeroTier service in daemon mode after building from source. Requires superuser privileges. ```bash sudo ./zerotier-one -d ``` -------------------------------- ### Example Bazel Build and Run Commands Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/google-test.md Specific commands for building and running the `tracer_provider_test` example within the OpenTelemetry C++ SDK trace test package. ```console bazel build //sdk/test/trace:tracer_provider_test ``` ```console bazel-bin/sdk/test/trace/tracer_provider_test ``` -------------------------------- ### Install OpenTelemetry C++ SDK using a Response File (Linux) Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/building-with-vcpkg.md Installs the OpenTelemetry C++ SDK and its dependencies by referencing a pre-defined response file, which consolidates installation parameters for Linux. ```console vcpkg install @tools/ports/opentelemetry/response_file_linux.txt ``` -------------------------------- ### Build Plugin Example with CMake Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/plugin/load/CMakeLists.txt Configures the build for a plugin example executable, linking against the OpenTelemetry API and the dynamic linking libraries. ```cmake add_executable(load_plugin_example main.cc) target_link_libraries(load_plugin_example PRIVATE opentelemetry-cpp::api ${CMAKE_DL_LIBS}) ``` -------------------------------- ### Configure OTLP gRPC Trace Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/otlp/CMakeLists.txt Adds an executable for the OTLP gRPC trace example and links necessary libraries. This is used when WITH_OTLP_GRPC is enabled. ```cmake add_executable(example_otlp_grpc grpc_main.cc) target_link_libraries(example_otlp_grpc PRIVATE common_foo_library) ``` -------------------------------- ### Install hiredis Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.1.1/README.md Clone the hiredis repository, build, and install it. The minimum version required is v0.12.1. ```bash git clone https://github.com/redis/hiredis.git cd hiredis make make install ``` ```bash make PREFIX=/non/default/path make PREFIX=/non/default/path install ``` -------------------------------- ### Configure OTLP File Trace Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/otlp/CMakeLists.txt Adds an executable for the OTLP file trace example and links the common foo library. This is used when WITH_OTLP_FILE is enabled. ```cmake add_executable(example_otlp_file file_main.cc) target_link_libraries(example_otlp_file PRIVATE common_foo_library) ``` -------------------------------- ### Execute GET Command with String Range Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Shows how to execute a GET command using a range of strings as arguments. The reply is parsed into an OptionalString. ```C++ // Arguments of the command can be a range of strings. auto get_cmd_strs = {"get", "key"}; r = redis.command(get_cmd_strs.begin(), get_cmd_strs.end()); val = reply::parse(*r); ``` -------------------------------- ### Configure OTLP HTTP Trace Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/otlp/CMakeLists.txt Adds an executable for the OTLP HTTP trace example and links the common foo library. This is used when WITH_OTLP_HTTP is enabled. ```cmake add_executable(example_otlp_http http_main.cc) target_link_libraries(example_otlp_http PRIVATE common_foo_library) ``` -------------------------------- ### Install OpenTelemetry C++ Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/INSTALL.md Optionally install the header files for the API and the generated targets and header files for the SDK to a specified or default location. ```console cmake --install . --prefix "//" ``` -------------------------------- ### Change Collector Endpoint Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/otlp/README.md Demonstrates how to change the collector endpoint for OTLP gRPC and HTTP exporters by providing them as command-line arguments to the example binary. ```bash ./example_otlp_grpc gateway.docker.internal:4317 ``` ```bash ./example_otlp_http gateway.docker.internal:4318/v1/traces ``` -------------------------------- ### Find Installed OpenTelemetry C++ Package Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/INSTALL.md Use `find_package` in an external CMake project to locate the installed OpenTelemetry C++ library and link its targets. This example shows finding all components. ```cmake find_package(opentelemetry-cpp CONFIG REQUIRED) ... target_include_directories(foo PRIVATE ${OPENTELEMETRY_CPP_INCLUDE_DIRS}) target_link_libraries(foo PRIVATE ${OPENTELEMETRY_CPP_LIBRARIES}) ``` -------------------------------- ### Example ZeroTier local.conf Configuration Source: https://github.com/zerotier/zerotierone/blob/dev/service/README.md This example demonstrates a practical application of the local.conf settings, including blacklisting a physical network, defining a trusted path for a specific network, and configuring software update behavior. ```javascript { "physical": { "10.0.0.0/24": { "blacklist": true }, "10.10.10.0/24": { "trustedPathId": 101010024 }, }, "virtual": { "feedbeef12": { "role": "UPSTREAM", "try": [ "10.10.20.1/9993" ], "blacklist": [ "192.168.0.0/24" ] } }, "settings": { "softwareUpdate": "apply", "softwareUpdateChannel": "release" } } ``` -------------------------------- ### Define Executable and Link Libraries Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/simple/CMakeLists.txt Defines the main executable for the example and links a common library. This is a standard CMake setup for C++ projects. ```cmake add_executable(example_simple main.cc) target_link_libraries(example_simple PRIVATE common_foo_library) ``` -------------------------------- ### Execute Pipelined Redis Commands Source: https://github.com/zerotier/zerotierone/blob/dev/ext/hiredis-0.14.1/README.md After appending commands using redisAppendCommand or redisAppendCommandArgv, call redisGetReply to retrieve the replies. This example demonstrates pipelining SET and GET commands. ```c redisReply *reply; redisAppendCommand(context,"SET foo bar"); redisAppendCommand(context,"GET foo"); redisGetReply(context,&reply); // reply for SET freeReplyObject(reply); redisGetReply(context,&reply); // reply for GET freeReplyObject(reply); ``` -------------------------------- ### Execute Pipelined Commands in C Source: https://github.com/zerotier/zerotierone/blob/dev/ext/hiredis-1.0.2/README.md After appending commands using redisAppendCommand or redisAppendCommandArgv, call redisGetReply to retrieve replies. This example shows retrieving replies for SET and GET commands. ```c redisReply *reply; redisAppendCommand(context,"SET foo bar"); redisAppendCommand(context,"GET foo"); redisGetReply(context,(void *)&reply); // reply for SET freeReplyObject(reply); redisGetReply(context,(void *)&reply); // reply for GET freeReplyObject(reply); ``` -------------------------------- ### CMake Minimum Requirements and Project Setup Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/install/test/cmake/component_tests/exporters_otlp_file/CMakeLists.txt Sets the minimum required CMake version and defines the project name for the OpenTelemetry C++ OTLP file exporter installation tests. ```cmake cmake_minimum_required(VERSION 3.14) project(opentelemetry-cpp-exporters-otlp-file-install-test LANGUAGES CXX) ``` -------------------------------- ### CMake Minimum Version and Project Setup Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/install/test/cmake/component_tests/exporters_otlp_common/CMakeLists.txt Sets the minimum required CMake version and defines the project name and languages for the OpenTelemetry C++ OTLP common exporter installation tests. ```cmake cmake_minimum_required(VERSION 3.14) project(opentelemetry-cpp-exporters-otlp-common-install-test LANGUAGES CXX) ``` -------------------------------- ### Setup Build Environment (Linux/Mac) Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/using-clang-format.md Execute this command on Linux and Mac to set up the build tools environment, adding them to the PATH. ```shell . tools/setup-devenv.sh ``` -------------------------------- ### Async Redis with Boost Future Continuation Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Example of using boost::future's continuation feature with redis-plus-plus for asynchronous Redis GET operations. Link boost libraries when building your application. ```cpp #include ConnectionOptions opts; opts.host = "127.0.0.1"; opts.port = 6379; auto redis = AsyncRedis(opts); auto fut = redis.get("key").then([](sw::redis::Future> fut) { auto val = fut.get(); if (val) cout << *val << endl; }); // Do other things // Wait for the continuation finishes. fut.get(); ``` -------------------------------- ### Setup Build Environment (Windows) Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/using-clang-format.md Run this command on Windows to set up the build tools environment, which adds necessary tools to the PATH. ```batch call tools\setup-devenv.cmd ``` -------------------------------- ### Basic RedisCluster Operations and Hash-Tagging Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Demonstrates basic RedisCluster operations like SET, GET, and MGET using hash tags to ensure keys are processed on the same node. Also shows list operations like LPUSH and LRANGE. ```cpp #include using namespace sw::redis; auto redis_cluster = RedisCluster("tcp://127.0.0.1:7000"); redis_cluster.set("key", "value"); auto val = redis_cluster.get("key"); if (val) { std::cout << *val << std::endl; } // With hash-tag. redis_cluster.set("key{tag}1", "val1"); redis_cluster.set("key{tag}2", "val2"); redis_cluster.set("key{tag}3", "val3"); std::vector hash_tag_res; redis_cluster.mget({"key{tag}1", "key{tag}2", "key{tag}3"}, std::back_inserter(hash_tag_res)); redis_cluster.lpush("list", {"1", "2", "3"}); std::vector list; redis_cluster.lrange("list", 0, -1, std::back_inserter(list)); ``` -------------------------------- ### Basic Redis Operations with Redis++ Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Demonstrates fundamental Redis commands like SET, GET, RPUSH, LRANGE, HSET, HGETALL, SADD, SMEMBERS, and ZADD using the Redis++ library. Includes examples for converting C++ data structures to Redis types and vice versa. Ensure Redis is running on the default port. ```C++ #include using namespace sw::redis; try { // Create an Redis object, which is movable but NOT copyable. auto redis = Redis("tcp://127.0.0.1:6379"); // ***** STRING commands ***** redis.set("key", "val"); auto val = redis.get("key"); // val is of type OptionalString. See 'API Reference' section for details. if (val) { // Dereference val to get the returned value of std::string type. std::cout << *val << std::endl; } // else key doesn't exist. // ***** LIST commands ***** // std::vector to Redis LIST. std::vector vec = {"a", "b", "c"}; redis.rpush("list", vec.begin(), vec.end()); // std::initializer_list to Redis LIST. redis.rpush("list", {"a", "b", "c"}); // Redis LIST to std::vector. vec.clear(); redis.lrange("list", 0, -1, std::back_inserter(vec)); // ***** HASH commands ***** redis.hset("hash", "field", "val"); // Another way to do the same job. redis.hset("hash", std::make_pair("field", "val")); // std::unordered_map to Redis HASH. std::unordered_map m = { {"field1", "val1"}, {"field2", "val2"} }; redis.hmset("hash", m.begin(), m.end()); // Redis HASH to std::unordered_map. m.clear(); redis.hgetall("hash", std::inserter(m, m.begin())); // Get value only. // NOTE: since field might NOT exist, so we need to parse it to OptionalString. std::vector vals; redis.hmget("hash", {"field1", "field2"}, std::back_inserter(vals)); // ***** SET commands ***** redis.sadd("set", "m1"); // std::unordered_set to Redis SET. std::unordered_set set = {"m2", "m3"}; redis.sadd("set", set.begin(), set.end()); // std::initializer_list to Redis SET. redis.sadd("set", {"m2", "m3"}); // Redis SET to std::unordered_set. set.clear(); redis.smembers("set", std::inserter(set, set.begin())); if (redis.sismember("set", "m1")) { std::cout << "m1 exists" << std::endl; } // else NOT exist. // ***** SORTED SET commands ***** redis.zadd("sorted_set", "m1", 1.3); // std::unordered_map to Redis SORTED SET. std::unordered_map scores = { {"m2", 2.3}, {"m3", 4.5} }; redis.zadd("sorted_set", scores.begin(), scores.end()); // Redis SORTED SET to std::vector>. // NOTE: The return results of zrangebyscore are ordered, if you save the results // in to `std::unordered_map`, you'll lose the order. std::vector> zset_result; redis.zrangebyscore("sorted_set", UnboundedInterval{}, // (-inf, +inf) std::back_inserter(zset_result)); // Only get member names: // pass an inserter of std::vector type as output parameter. std::vector without_score; redis.zrangebyscore("sorted_set", BoundedInterval(1.5, 3.4, BoundType::CLOSED), // [1.5, 3.4] std::back_inserter(without_score)); // Get both member names and scores: // pass an back_inserter of std::vector> as output parameter. std::vector> with_score; redis.zrangebyscore("sorted_set", BoundedInterval(1.5, 3.4, BoundType::LEFT_OPEN), // (1.5, 3.4] std::back_inserter(with_score)); // ***** SCRIPTING commands ***** // Script returns a single element. auto num = redis.eval("return 1", {}, {}); // Script returns an array of elements. std::vector nums; redis.eval("return {ARGV[1], ARGV[2]}", {}, {"1", "2"}, std::back_inserter(nums)); // mset with TTL auto mset_with_ttl_script = R"( local len = #KEYS if (len == 0 or len + 1 ~= #ARGV) then return 0 end local ttl = tonumber(ARGV[len + 1]) if (not ttl or ttl <= 0) then return 0 end for i = 1, len do redis.call("SET", KEYS[i], ARGV[i], "EX", ttl) end return 1 )"; // Set multiple key-value pairs with TTL of 60 seconds. auto keys = {"key1", "key2", "key3"}; std::vector args = {"val1", "val2", "val3", "60"}; redis.eval(mset_with_ttl_script, keys.begin(), keys.end(), vals.begin(), vals.end()); // ***** Pipeline ***** // Create a pipeline. auto pipe = redis.pipeline(); // Send mulitple commands and get all replies. auto pipe_replies = pipe.set("key", "value") .get("key") .rename("key", "new-key") .rpush("list", {"a", "b", "c"}) ``` -------------------------------- ### Start HTTP Server Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/examples/http/README.md Run the HTTP server from the `examples/http` directory. Ensure OpenTelemetry C++ is built and deployed. ```console $ http_server 8800 Server is running..Press ctrl-c to exit... ``` -------------------------------- ### Install hiredis to a custom path Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Install hiredis to a non-default location by specifying a prefix. This is useful for managing multiple installations or avoiding system-wide installations. ```bash make PREFIX=/non/default/path make PREFIX=/non/default/path install ``` -------------------------------- ### Basic PostgreSQL Interaction with libpqxx Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/README.md This example demonstrates connecting to a PostgreSQL database, performing a query to select employee names, updating salaries, and committing the transaction. It includes basic error handling. Ensure you have a PostgreSQL server running and a database with an 'employee' table containing 'name' and 'salary' columns. ```cpp #include #include int main() { try { // Connect to the database. pqxx::connection C; std::cout << "Connected to " << C.dbname() << '\n'; // Start a transaction. pqxx::work W{C}; // Perform a query and retrieve all results. pqxx::result R{W.exec("SELECT name FROM employee")}; // Iterate over results. std::cout << "Found " << R.size() << "employees:\n"; for (auto row: R) std::cout << row[0].c_str() << '\n'; // Perform a query and check that it returns no result. std::cout << "Doubling all employees' salaries...\n"; W.exec0("UPDATE employee SET salary = salary*2"); // Commit the transaction. std::cout << "Making changes definite: "; W.commit(); std::cout << "OK.\n"; } catch (std::exception const &e) { std::cerr << e.what() << '\n'; return 1; } return 0; } ``` -------------------------------- ### Start ZeroTier Service Daemon (`zerotier-one`) Source: https://context7.com/zerotier/zerotierone/llms.txt Use `zerotier-one` to run the ZeroTier service. It requires root privileges and manages network connections. Specify custom working directories and ports as needed. ```bash sudo zerotier-one -d ``` ```bash sudo zerotier-one -d -p12345 /tmp/zerotier-working-directory-test ``` ```bash zerotier-one -v ``` ```bash zerotier-one -h ``` ```bash zerotier-one -U ``` ```bash sudo touch /var/lib/zerotier-one/networks.d/8056c2e21c000001.conf ``` -------------------------------- ### Install redis-plus-plus Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.1.1/README.md Clone the redis-plus-plus repository, configure with CMake, build, and install. Use CMAKE_PREFIX_PATH if hiredis is installed in a non-default location. ```bash git clone https://github.com/sewenew/redis-plus-plus.git cd redis-plus-plus mkdir compile cd compile cmake -DCMAKE_BUILD_TYPE=Release .. make make install cd .. ``` ```bash cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/path/to/hiredis -DCMAKE_INSTALL_PREFIX=/path/to/install/redis-plus-plus .. ``` -------------------------------- ### Redis Pipeline Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Demonstrates how to use a Redis pipeline to execute multiple commands and retrieve their results. Ensure proper error handling for each command's reply. ```cpp auto pipe_replies = pipe.incr("num") .lpush("list", "a") .expire("list", 100) .lrange("list", 0, -1) .exec(); // Parse reply with reply type and index. auto set_cmd_result = pipe_replies.get(0); auto get_cmd_result = pipe_replies.get(1); // rename command result pipe_replies.get(2); auto rpush_cmd_result = pipe_replies.get(3); std::vector lrange_cmd_result; pipe_replies.get(4, back_inserter(lrange_cmd_result)); ``` -------------------------------- ### Application Instrumentation Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/abi-version-policy.md Shows how an application would use the fictitious OtelUtil class. This demonstrates the direct usage of the API. ```cpp opentelemetry::common::OtelUtil *p = ...; p->DoSomething(); ``` -------------------------------- ### Specify Hiredis and Install Paths Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Use CMAKE_PREFIX_PATH to specify the hiredis installation location and CMAKE_INSTALL_PREFIX to set the installation directory for redis-plus-plus if they are not in default locations. ```bash cmake -DCMAKE_PREFIX_PATH=/path/to/hiredis -DCMAKE_INSTALL_PREFIX=/path/to/install/redis-plus-plus .. ``` -------------------------------- ### Get ZeroTier CLI Help Source: https://github.com/zerotier/zerotierone/wiki/Command-Line-Interface Run this command to display a list of available command-line switches and commands for zerotier-cli. ```bash sudo zerotier-cli help ``` -------------------------------- ### Install Google Test with CMake Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/google-test.md Commands to build and install Google Test using CMake. Ensure you have CMake installed and download the Google Test source code. ```console mkdir build && cd build cmake .. make make install ``` -------------------------------- ### Basic CMake Configuration Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-cmake.md Configure the libpqxx build by running CMake from a separate build directory, pointing it to the source directory. ```shell cd $BUILD cmake $SRC ``` -------------------------------- ### Initialize Hiredis SSL Context and Connect Source: https://github.com/zerotier/zerotierone/blob/dev/ext/hiredis-1.0.2/README.md Demonstrates initializing an Hiredis SSL context with certificate files and paths, then connecting to a Redis server and initiating the SSL/TLS handshake. ```c /* An Hiredis SSL context. It holds SSL configuration and can be reused across * many contexts. */ redisSSLContext *ssl; /* An error variable to indicate what went wrong, if the context fails to * initialize. */ redisSSLContextError ssl_error; /* Initialize global OpenSSL state. * * You should call this only once when your app initializes, and only if * you don't explicitly or implicitly initialize OpenSSL it elsewhere. */ redisInitOpenSSL(); /* Create SSL context */ ssl = redisCreateSSLContext( "cacertbundle.crt", /* File name of trusted CA/ca bundle file, optional */ "/path/to/certs", /* Path of trusted certificates, optional */ "client_cert.pem", /* File name of client certificate file, optional */ "client_key.pem", /* File name of client private key, optional */ "redis.mydomain.com", /* Server name to request (SNI), optional */ &ssl_error ) != REDIS_OK) { printf("SSL error: %s\n", redisSSLContextGetError(ssl_error); /* Abort... */ } /* Create Redis context and establish connection */ c = redisConnect("localhost", 6443); if (c == NULL || c->err) { /* Handle error and abort... */ } /* Negotiate SSL/TLS */ if (redisInitiateSSLWithContext(c, ssl) != REDIS_OK) { /* Handle error, in c->err / c->errstr */ } ``` -------------------------------- ### Basic Configure Command Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-configure.md Navigate to your build directory and run the configure script. Add options as needed. ```shell cd $BUILD $SRC/configure ``` -------------------------------- ### Install OpenTelemetry C++ SDK using a Response File (macOS) Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/building-with-vcpkg.md Installs the OpenTelemetry C++ SDK and its dependencies by referencing a pre-defined response file, which consolidates installation parameters for macOS. ```console vcpkg install @tools/ports/opentelemetry/response_file_mac.txt ``` -------------------------------- ### Initializing Redis Connection with Options Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.1.1/README.md Demonstrates how to initialize a Redis instance with ConnectionOptions and optional ConnectionPoolOptions for managing connections to a Redis server. ```APIDOC ## Initializing Redis Connection with Options ### Description Initialize a `Redis` instance with `ConnectionOptions` and `ConnectionPoolOptions`. `ConnectionOptions` specifies connection details, and `ConnectionPoolOptions` configures the connection pool. If `ConnectionPoolOptions` is omitted, a single connection is maintained. ### Code Example ```C++ #include "sw/redis++/redis++.h" using namespace sw::redis; int main() { ConnectionOptions connection_options; connection_options.host = "127.0.0.1"; // Required. Hostname or IP address of the Redis server. connection_options.port = 6666; // Optional. Default is 6379. connection_options.password = "auth"; // Optional. No password by default. connection_options.db = 1; // Optional. Default is database 0. // Optional. Timeout for sending requests or receiving responses. // Default is 0ms (no timeout). // A TimeoutError exception is thrown if any command times out. connection_options.socket_timeout = std::chrono::milliseconds(200); // Connect with a single connection. Redis redis1(connection_options); ConnectionPoolOptions pool_options; pool_options.size = 3; // Maximum number of connections in the pool. // Connect with a connection pool. Redis redis2(connection_options, pool_options); return 0; } ``` ### Notes - `Redis` class is movable but not copyable. - Connections are lazily created and established only when a command is first sent. - Connection failures result in `Error` exceptions, but the `Redis` object can be reused to automatically attempt reconnection. ``` -------------------------------- ### Redis Subscriber Example Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Demonstrates how to create a Subscriber, set message and metadata callback functions, subscribe to channels and patterns, and consume messages. ```C++ // Create a Subscriber. auto sub = redis.subscriber(); // Set callback functions. sub.on_message([](std::string channel, std::string msg) { // Process message of MESSAGE type. }); sub.on_pmessage([](std::string pattern, std::string channel, std::string msg) { // Process message of PMESSAGE type. }); sub.on_meta([](Subscriber::MsgType type, OptionalString channel, long long num) { // Process message of META type. }); // Subscribe to channels and patterns. sub.subscribe("channel1"); sub.subscribe({"channel2", "channel3"}); sub.psubscribe("pattern1*"); // Consume messages in a loop. while (true) { try { sub.consume(); } catch (const Error &err) { // Handle exceptions. } } ``` -------------------------------- ### Build ZeroTier One with MSBuild Source: https://github.com/zerotier/zerotierone/blob/dev/windows/README.md Use MSBuild to compile the ZeroTierOne solution in Release configuration for ARM64 architecture. Substitute configuration and platform as needed. ```bash MSBuild ZeroTierOne.sln /property:Configuration=Release /property:Platform=ARM64 ``` -------------------------------- ### Basic String Operations Source: https://github.com/zerotier/zerotierone/blob/dev/ext/redis-plus-plus-1.3.3/README.md Demonstrates setting and getting string values in Redis using the `set` and `get` commands. ```APIDOC ## STRING commands ### Description Set a key-value pair and retrieve the value associated with a key. ### Method `set(key, value)` `get(key)` ### Parameters #### `set` command - **key** (string) - The key to set. - **value** (string) - The value to associate with the key. #### `get` command - **key** (string) - The key to retrieve. ### Response - `set` command returns void. - `get` command returns `OptionalString` which contains the value if the key exists, otherwise it's empty. ### Request Example ```cpp redis.set("key", "val"); auto val = redis.get("key"); if (val) { std::cout << *val << std::endl; } ``` ``` -------------------------------- ### CMake: Install Test Runner Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/test/CMakeLists.txt Conditionally installs the test runner executable to the binary directory if the INSTALL_TEST option is enabled. ```cmake if(INSTALL_TEST) install( PROGRAMS runner TYPE BIN RENAME libpqxx-test-runner ) endif() ``` -------------------------------- ### Running the libpqxx Test Suite Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-configure.md Execute the test suite to verify the library's functionality. Ensure a database is accessible for the tests to create and drop tables. ```shell make check ``` ```shell make check -j$(nproc) ``` -------------------------------- ### Install OpenTelemetry C++ SDK with Abseil features Source: https://github.com/zerotier/zerotierone/blob/dev/ext/opentelemetry-cpp-1.21.0/docs/building-with-vcpkg.md Installs the OpenTelemetry C++ SDK with support for Abseil API surface classes. ```console vcpkg install opentelemetry[abseil] ``` -------------------------------- ### Configure with Disabled Documentation and No Optimization Source: https://github.com/zerotier/zerotierone/blob/dev/ext/libpqxx-7.7.3/BUILDING-configure.md Use this command to quickly build libpqxx with optimizations disabled, resulting in slower code but a faster build process. ```shell ./configure --disable-documentation CXXFLAGS=-O0 ``` -------------------------------- ### Configuring Inja Environment Source: https://github.com/zerotier/zerotierone/blob/dev/ext/inja/README.md Demonstrates how to configure the Inja Environment with different paths and custom syntax for template elements. ```cpp // With default settings Environment env_default; // With global path to template files and where files will be saved Environment env_1 {"../path/templates/"}; // With separate input and output path Environment env_2 {"../path/templates/", "../path/results/"}; // With other opening and closing strings (here the defaults) env.set_expression("{{ " , " }}"); // Expressions env.set_comment("{#", "#}"); // Comments env.set_statement("{%", "%}"); // Statements {% %} for many things, see below env.set_line_statement("##"); // Line statements ## (just an opener) ```