blob: 1a40f906585ad474f0b01af5a1a931f404378433 [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
17#include "private/redis/asynccommanddispatcher.hpp"
18#include <cstdlib>
19#include "config.h"
20#include "private/redis/databaseinfo.hpp"
21#if HAVE_HIREDIS_VIP
22#include "private/redis/asynchiredisclustercommanddispatcher.hpp"
23#include "private/redis/asynchirediscommanddispatcher.hpp"
24#elif HAVE_HIREDIS
25#include "private/redis/asynchirediscommanddispatcher.hpp"
26#endif
27#include "private/abort.hpp"
28#include "private/engine.hpp"
29
30using namespace shareddatalayer::redis;
31
32std::shared_ptr<AsyncCommandDispatcher> AsyncCommandDispatcher::create(Engine& engine,
33 const DatabaseInfo& databaseInfo,
34 std::shared_ptr<ContentsBuilder> contentsBuilder,
35 bool usePermanentCommandCallbacks,
Rolf Badorek8324d022019-09-17 16:47:20 +030036 std::shared_ptr<Logger> logger,
37 bool usedForSentinel)
Rolf Badorekef2bf512019-08-20 11:17:15 +030038{
39#if HAVE_HIREDIS_VIP
Rolf Badorek8324d022019-09-17 16:47:20 +030040 static_cast<void>(usedForSentinel);
Rolf Badorekef2bf512019-08-20 11:17:15 +030041 if (databaseInfo.type == DatabaseInfo::Type::CLUSTER)
42 {
43 return std::make_shared<AsyncHiredisClusterCommandDispatcher>(engine,
44 databaseInfo.ns,
45 databaseInfo.hosts,
46 contentsBuilder,
47 usePermanentCommandCallbacks,
48 logger);
49 }
50 else
51 return std::make_shared<AsyncHiredisCommandDispatcher>(engine,
52 databaseInfo.hosts.at(0).getHost(),
53 databaseInfo.hosts.at(0).getPort(),
54 contentsBuilder,
55 usePermanentCommandCallbacks,
56 logger);
57#elif HAVE_HIREDIS
58 if (databaseInfo.type == DatabaseInfo::Type::CLUSTER)
59 SHAREDDATALAYER_ABORT("Not implemented.");
60 return std::make_shared<AsyncHiredisCommandDispatcher>(engine,
61 databaseInfo.hosts.at(0).getHost(),
62 databaseInfo.hosts.at(0).getPort(),
63 contentsBuilder,
64 usePermanentCommandCallbacks,
Rolf Badorek8324d022019-09-17 16:47:20 +030065 logger,
66 usedForSentinel);
Rolf Badorekef2bf512019-08-20 11:17:15 +030067#else
68 SHAREDDATALAYER_ABORT("Not implemented.");
69#endif
70}