blob: a549bc9cad60b90b87c63dae34bfaeeaf35f96d8 [file] [log] [blame]
Rolf Badorekef2bf512019-08-20 11:17:15 +03001/*
2 Copyright (c) 2018-2019 Nokia.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
Timo Tietavainena0745d22019-11-28 09:55:22 +020017/*
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
20*/
21
Rolf Badorekef2bf512019-08-20 11:17:15 +030022#include "private/redis/asynccommanddispatcher.hpp"
23#include <cstdlib>
24#include "config.h"
25#include "private/redis/databaseinfo.hpp"
26#if HAVE_HIREDIS_VIP
27#include "private/redis/asynchiredisclustercommanddispatcher.hpp"
28#include "private/redis/asynchirediscommanddispatcher.hpp"
29#elif HAVE_HIREDIS
30#include "private/redis/asynchirediscommanddispatcher.hpp"
31#endif
32#include "private/abort.hpp"
33#include "private/engine.hpp"
34
35using namespace shareddatalayer::redis;
36
37std::shared_ptr<AsyncCommandDispatcher> AsyncCommandDispatcher::create(Engine& engine,
38 const DatabaseInfo& databaseInfo,
39 std::shared_ptr<ContentsBuilder> contentsBuilder,
40 bool usePermanentCommandCallbacks,
Rolf Badorek8324d022019-09-17 16:47:20 +030041 std::shared_ptr<Logger> logger,
42 bool usedForSentinel)
Rolf Badorekef2bf512019-08-20 11:17:15 +030043{
44#if HAVE_HIREDIS_VIP
Rolf Badorek8324d022019-09-17 16:47:20 +030045 static_cast<void>(usedForSentinel);
Rolf Badorekef2bf512019-08-20 11:17:15 +030046 if (databaseInfo.type == DatabaseInfo::Type::CLUSTER)
47 {
48 return std::make_shared<AsyncHiredisClusterCommandDispatcher>(engine,
49 databaseInfo.ns,
50 databaseInfo.hosts,
51 contentsBuilder,
52 usePermanentCommandCallbacks,
53 logger);
54 }
55 else
56 return std::make_shared<AsyncHiredisCommandDispatcher>(engine,
57 databaseInfo.hosts.at(0).getHost(),
58 databaseInfo.hosts.at(0).getPort(),
59 contentsBuilder,
60 usePermanentCommandCallbacks,
61 logger);
62#elif HAVE_HIREDIS
63 if (databaseInfo.type == DatabaseInfo::Type::CLUSTER)
64 SHAREDDATALAYER_ABORT("Not implemented.");
65 return std::make_shared<AsyncHiredisCommandDispatcher>(engine,
66 databaseInfo.hosts.at(0).getHost(),
67 databaseInfo.hosts.at(0).getPort(),
68 contentsBuilder,
69 usePermanentCommandCallbacks,
Rolf Badorek8324d022019-09-17 16:47:20 +030070 logger,
71 usedForSentinel);
Rolf Badorekef2bf512019-08-20 11:17:15 +030072#else
73 SHAREDDATALAYER_ABORT("Not implemented.");
74#endif
75}