Skip to content
This repository was archived by the owner on Apr 6, 2019. It is now read-only.

Commit f12dd9e

Browse files
author
Simon Ninon
committed
seems like dump msvc does not handle ipp+enable_if+enum. yay, come one, it is 2017 dude.
1 parent fb9675e commit f12dd9e

File tree

2 files changed

+77
-136
lines changed

2 files changed

+77
-136
lines changed

includes/cpp_redis/impl/redis_client.ipp

Lines changed: 0 additions & 120 deletions
This file was deleted.

includes/cpp_redis/redis_client.hpp

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ class redis_client {
105105
redis_client& blpop(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback = nullptr);
106106
redis_client& brpop(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback = nullptr);
107107
redis_client& brpoplpush(const std::string& src, const std::string& dst, int timeout, const reply_callback_t& reply_callback = nullptr);
108-
template <typename T, typename... Ts>
109-
redis_client& client_kill(const std::string& host, int port, const T& arg, const Ts&... args);
110-
redis_client& client_kill(const std::string& host, int port);
111-
template <typename... Ts>
112-
redis_client& client_kill(const char* host, int port, const Ts&... args);
113-
template <typename T, typename... Ts>
114-
redis_client& client_kill(const T&, const Ts&...);
115108
redis_client& client_list(const reply_callback_t& reply_callback = nullptr);
116109
redis_client& client_getname(const reply_callback_t& reply_callback = nullptr);
117110
redis_client& client_pause(int timeout, const reply_callback_t& reply_callback = nullptr);
@@ -319,31 +312,101 @@ class redis_client {
319312
// redis_client& hscan(const reply_callback_t& reply_callback = nullptr) key cursor [match pattern] [count count]
320313
// redis_client& zscan(const reply_callback_t& reply_callback = nullptr) key cursor [match pattern] [count count]
321314

315+
public:
316+
//! client kill
317+
template <typename T, typename... Ts>
318+
inline redis_client&
319+
client_kill(const T& arg, const Ts&... args) {
320+
static_assert(helpers::is_different_types<T, Ts...>::value, "Should only have one distinct value per filter type");
321+
static_assert(!(std::is_class<T>::value && std::is_same<T, typename helpers::back<T, Ts...>::type>::value), "Should have at least one filter");
322+
323+
std::vector<std::string> redis_cmd({"CLIENT", "KILL"});
324+
reply_callback_t reply_cb = nullptr;
325+
client_kill_impl<T, Ts...>(redis_cmd, reply_cb, arg, args...);
326+
327+
return send(redis_cmd, reply_cb);
328+
}
329+
330+
template <typename T, typename... Ts>
331+
inline redis_client&
332+
client_kill(const std::string& host, int port, const T& arg, const Ts&... args) {
333+
static_assert(helpers::is_different_types<T, Ts...>::value, "Should only have one distinct value per filter type");
334+
std::vector<std::string> redis_cmd({"CLIENT", "KILL"});
335+
336+
//! If we have other type than lambda, then it's a filter
337+
if (!std::is_class<T>::value) {
338+
redis_cmd.emplace_back("ADDR");
339+
}
340+
341+
redis_cmd.emplace_back(host + ":" + std::to_string(port));
342+
reply_callback_t reply_cb = nullptr;
343+
client_kill_impl<T, Ts...>(redis_cmd, reply_cb, arg, args...);
344+
345+
return send(redis_cmd, reply_cb);
346+
}
347+
348+
inline redis_client&
349+
client_kill(const std::string& host, int port) {
350+
return client_kill(host, port, reply_callback_t(nullptr));
351+
}
352+
353+
template <typename... Ts>
354+
inline redis_client&
355+
client_kill(const char* host, int port, const Ts&... args) {
356+
return client_kill(std::string(host), port, args...);
357+
}
358+
322359
private:
323-
//! client kill impl
360+
//! client kill internal impl
324361
template <typename T>
325362
typename std::enable_if<std::is_same<T, enum type>::value>::type
326-
client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, enum type type);
363+
client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, enum type type) {
364+
redis_cmd.emplace_back("TYPE");
365+
std::string type_string;
366+
367+
switch (type) {
368+
case type::normal: type_string = "normal"; break;
369+
case type::master: type_string = "master"; break;
370+
case type::pubsub: type_string = "pubsub"; break;
371+
case type::slave: type_string = "slave"; break;
372+
}
373+
374+
redis_cmd.emplace_back(type_string);
375+
}
327376

328377
template <typename T>
329378
typename std::enable_if<std::is_same<T, bool>::value>::type
330-
client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, bool skip);
379+
client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, bool skip) {
380+
redis_cmd.emplace_back("SKIPME");
381+
redis_cmd.emplace_back(skip ? "yes" : "no");
382+
}
331383

332384
template <typename T>
333385
typename std::enable_if<std::is_integral<T>::value>::type
334-
client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, uint64_t id);
386+
client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, uint64_t id) {
387+
redis_cmd.emplace_back("ID");
388+
redis_cmd.emplace_back(std::to_string(id));
389+
}
335390

336391
template <typename T>
337392
typename std::enable_if<std::is_class<T>::value>::type
338-
client_kill_unpack_arg(std::vector<std::string>&, reply_callback_t& reply_callback, const T& cb);
393+
client_kill_unpack_arg(std::vector<std::string>&, reply_callback_t& reply_callback, const T& cb) {
394+
reply_callback = cb;
395+
}
339396

340397
template <typename T, typename... Ts>
341398
void
342-
client_kill_impl(std::vector<std::string>& redis_cmd, reply_callback_t& reply, const T& arg, const Ts&... args);
399+
client_kill_impl(std::vector<std::string>& redis_cmd, reply_callback_t& reply, const T& arg, const Ts&... args) {
400+
static_assert(!std::is_class<T>::value, "Reply callback should be in the end of the argument list");
401+
client_kill_unpack_arg<T>(redis_cmd, reply, arg);
402+
client_kill_impl(redis_cmd, reply, args...);
403+
};
343404

344405
template <typename T>
345406
void
346-
client_kill_impl(std::vector<std::string>& redis_cmd, reply_callback_t& reply, const T& arg);
407+
client_kill_impl(std::vector<std::string>& redis_cmd, reply_callback_t& reply, const T& arg) {
408+
client_kill_unpack_arg<T>(redis_cmd, reply, arg);
409+
};
347410

348411
private:
349412
//! receive & disconnection handlers
@@ -376,5 +439,3 @@ class redis_client {
376439
};
377440

378441
} // namespace cpp_redis
379-
380-
#include <cpp_redis/impl/redis_client.ipp>

0 commit comments

Comments
 (0)