Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 09:00:18

0001 /* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com)
0002  *
0003  * Distributed under the Boost Software License, Version 1.0. (See
0004  * accompanying file LICENSE.txt)
0005  */
0006 
0007 #ifndef BOOST_REDIS_SETUP_REQUEST_UTILS_HPP
0008 #define BOOST_REDIS_SETUP_REQUEST_UTILS_HPP
0009 
0010 #include <boost/redis/config.hpp>
0011 #include <boost/redis/request.hpp>
0012 #include <boost/redis/response.hpp>
0013 
0014 namespace boost::redis::detail {
0015 
0016 // Modifies config::setup to make a request suitable to be sent
0017 // to the server using async_exec
0018 inline void compose_setup_request(config& cfg)
0019 {
0020    if (!cfg.use_setup) {
0021       // We're not using the setup request as-is, but should compose one based on
0022       // the values passed by the user
0023       auto& req = cfg.setup;
0024       req.clear();
0025 
0026       // Which parts of the command should we send?
0027       // Don't send AUTH if the user is the default and the password is empty.
0028       // Other users may have empty passwords.
0029       // Note that this is just an optimization.
0030       bool send_auth = !(
0031          cfg.username.empty() || (cfg.username == "default" && cfg.password.empty()));
0032       bool send_setname = !cfg.clientname.empty();
0033 
0034       // Gather everything we can in a HELLO command
0035       if (send_auth && send_setname)
0036          req.push("HELLO", "3", "AUTH", cfg.username, cfg.password, "SETNAME", cfg.clientname);
0037       else if (send_auth)
0038          req.push("HELLO", "3", "AUTH", cfg.username, cfg.password);
0039       else if (send_setname)
0040          req.push("HELLO", "3", "SETNAME", cfg.clientname);
0041       else
0042          req.push("HELLO", "3");
0043 
0044       // SELECT is independent of HELLO
0045       if (cfg.database_index && cfg.database_index.value() != 0)
0046          req.push("SELECT", cfg.database_index.value());
0047    }
0048 
0049    // In any case, the setup request should have the priority
0050    // flag set so it's executed before any other request.
0051    // The setup request should never be retried.
0052    request_access::set_priority(cfg.setup, true);
0053    cfg.setup.get_config().cancel_if_unresponded = true;
0054    cfg.setup.get_config().cancel_on_connection_lost = true;
0055 }
0056 
0057 }  // namespace boost::redis::detail
0058 
0059 #endif  // BOOST_REDIS_RUNNER_HPP