config.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Copyright (c) 2018-2023 Marcelo Zimbres Silva ([email protected])
  2. *
  3. * Distributed under the Boost Software License, Version 1.0. (See
  4. * accompanying file LICENSE.txt)
  5. */
  6. #ifndef BOOST_REDIS_CONFIG_HPP
  7. #define BOOST_REDIS_CONFIG_HPP
  8. #include <string>
  9. #include <chrono>
  10. #include <optional>
  11. namespace boost::redis
  12. {
  13. /** @brief Address of a Redis server
  14. * @ingroup high-level-api
  15. */
  16. struct address {
  17. /// Redis host.
  18. std::string host = "127.0.0.1";
  19. /// Redis port.
  20. std::string port = "6379";
  21. };
  22. /** @brief Configure parameters used by the connection classes
  23. * @ingroup high-level-api
  24. */
  25. struct config {
  26. /// Uses SSL instead of a plain connection.
  27. bool use_ssl = false;
  28. /// Address of the Redis server.
  29. address addr = address{"127.0.0.1", "6379"};
  30. /** @brief Username passed to the
  31. * [HELLO](https://redis.io/commands/hello/) command. If left
  32. * empty `HELLO` will be sent without authentication parameters.
  33. */
  34. std::string username = "default";
  35. /** @brief Password passed to the
  36. * [HELLO](https://redis.io/commands/hello/) command. If left
  37. * empty `HELLO` will be sent without authentication parameters.
  38. */
  39. std::string password;
  40. /// Client name parameter of the [HELLO](https://redis.io/commands/hello/) command.
  41. std::string clientname = "Boost.Redis";
  42. /// Database that will be passed to the [SELECT](https://redis.io/commands/hello/) command.
  43. std::optional<int> database_index = 0;
  44. /// Message used by the health-checker in `boost::redis::connection::async_run`.
  45. std::string health_check_id = "Boost.Redis";
  46. /// Logger prefix, see `boost::redis::logger`.
  47. std::string log_prefix = "(Boost.Redis) ";
  48. /// Time the resolve operation is allowed to last.
  49. std::chrono::steady_clock::duration resolve_timeout = std::chrono::seconds{10};
  50. /// Time the connect operation is allowed to last.
  51. std::chrono::steady_clock::duration connect_timeout = std::chrono::seconds{10};
  52. /// Time the SSL handshake operation is allowed to last.
  53. std::chrono::steady_clock::duration ssl_handshake_timeout = std::chrono::seconds{10};
  54. /** Health checks interval.
  55. *
  56. * To disable health-checks pass zero as duration.
  57. */
  58. std::chrono::steady_clock::duration health_check_interval = std::chrono::seconds{2};
  59. /** @brief Time waited before trying a reconnection.
  60. *
  61. * To disable reconnection pass zero as duration.
  62. */
  63. std::chrono::steady_clock::duration reconnect_wait_interval = std::chrono::seconds{1};
  64. };
  65. } // boost::redis
  66. #endif // BOOST_REDIS_CONFIG_HPP