forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_factory.cc
48 lines (42 loc) · 1.62 KB
/
command_factory.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (C) 2019 pengjian.uestc @ gmail.com
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#include "redis/command_factory.hh"
#include "service/storage_proxy.hh"
#include "redis/commands.hh"
#include "utils/log.hh"
namespace redis {
static logging::logger logging("command_factory");
future<redis_message> command_factory::create_execute(service::storage_proxy& proxy, request& req, redis::redis_options& options, service_permit permit)
{
static thread_local std::unordered_map<bytes, std::function<future<redis_message> (service::storage_proxy& proxy, request& req, redis::redis_options& options, service_permit permit)>> _commands =
{
{ "ping", commands::ping },
{ "select", commands::select },
{ "get", commands::get },
{ "exists", commands::exists },
{ "ttl", commands::ttl },
{ "strlen", commands::strlen },
{ "set", commands::set },
{ "setex", commands::setex },
{ "del", commands::del },
{ "echo", commands::echo },
{ "lolwut", commands::lolwut },
{ "hget", commands::hget },
{ "hset", commands::hset },
{ "hgetall", commands::hgetall },
{ "hdel", commands::hdel },
{ "hexists", commands::hexists },
};
auto&& command = _commands.find(req._command);
if (command != _commands.end()) {
return (command->second)(proxy, req, options, permit);
}
auto& b = req._command;
logging.error("receive unknown command = {}", sstring(reinterpret_cast<const char*>(b.data()), b.size()));
return commands::unknown(proxy, req, options, permit);
}
}