limitations under the License.
*/
+/*
+ * This source code is part of the near-RT RIC (RAN Intelligent Controller)
+ * platform project (RICP).
+*/
+
#include "private/redis/asynchirediscommanddispatcher.hpp"
#include <algorithm>
#include <cstring>
uint16_t port,
std::shared_ptr<ContentsBuilder> contentsBuilder,
bool usePermanentCommandCallbacks,
- std::shared_ptr<Logger> logger):
+ std::shared_ptr<Logger> logger,
+ bool usedForSentinel):
AsyncHiredisCommandDispatcher(engine,
address,
port,
usePermanentCommandCallbacks,
HiredisSystem::getHiredisSystem(),
std::make_shared<HiredisEpollAdapter>(engine),
- logger)
+ logger,
+ usedForSentinel)
{
}
bool usePermanentCommandCallbacks,
HiredisSystem& hiredisSystem,
std::shared_ptr<HiredisEpollAdapter> adapter,
- std::shared_ptr<Logger> logger):
+ std::shared_ptr<Logger> logger,
+ bool usedForSentinel):
engine(engine),
address(address),
port(ntohs(port)),
connectionRetryTimer(engine),
connectionRetryTimerDuration(std::chrono::seconds(1)),
connectionVerificationRetryTimerDuration(std::chrono::seconds(10)),
- logger(logger)
+ logger(logger),
+ usedForSentinel(usedForSentinel)
{
connect();
void AsyncHiredisCommandDispatcher::verifyConnection()
{
- /* When Redis has max amount of users, it will still accept new connections but will
- * close them immediately. Therefore, we need to verify that just established connection
- * really works. This prevents calling client readyAck callback for a connection that
- * will be terminated immediately.
- */
- /* Connection verification is now done by doing redis command list query. Because we anyway
- * need to verify that Redis has required commands, we can now combine these two operations
- * (command list query and connection verification). If either one of the functionalities
- * is not needed in the future and it is removed, remember to still leave the other one.
- */
- serviceState = ServiceState::CONNECTION_VERIFICATION;
- /* Disarm retry timer as now we are connected to hiredis. This ensures timer disarm if
- * we are spontaneously connected to redis while timer is running. If connection verification
- * fails, timer is armed again (normal handling in connection verification).
- */
- connectionRetryTimer.disarm();
- dispatchAsync(std::bind(&AsyncHiredisCommandDispatcher::verifyConnectionReply,
- this,
- std::placeholders::_1,
- std::placeholders::_2),
- contentsBuilder->build("COMMAND"),
- false);
+ if (usedForSentinel)
+ setConnected();
+ else
+ {
+ /* When Redis has max amount of users, it will still accept new connections but will
+ * close them immediately. Therefore, we need to verify that just established connection
+ * really works. This prevents calling client readyAck callback for a connection that
+ * will be terminated immediately.
+ */
+ /* Connection verification is now done by doing redis command list query. Because we anyway
+ * need to verify that Redis has required commands, we can now combine these two operations
+ * (command list query and connection verification). If either one of the functionalities
+ * is not needed in the future and it is removed, remember to still leave the other one.
+ */
+ serviceState = ServiceState::CONNECTION_VERIFICATION;
+ /* Disarm retry timer as now we are connected to hiredis. This ensures timer disarm if
+ * we are spontaneously connected to redis while timer is running. If connection verification
+ * fails, timer is armed again (normal handling in connection verification).
+ */
+ connectionRetryTimer.disarm();
+ dispatchAsync(std::bind(&AsyncHiredisCommandDispatcher::verifyConnectionReply,
+ this,
+ std::placeholders::_1,
+ std::placeholders::_2),
+ contentsBuilder->build("COMMAND"),
+ false);
+ }
}
void AsyncHiredisCommandDispatcher::verifyConnectionReply(const std::error_code& error,