@@ -105,13 +105,6 @@ class redis_client {
105
105
redis_client& blpop (const std::vector<std::string>& keys, int timeout, const reply_callback_t & reply_callback = nullptr );
106
106
redis_client& brpop (const std::vector<std::string>& keys, int timeout, const reply_callback_t & reply_callback = nullptr );
107
107
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&...);
115
108
redis_client& client_list (const reply_callback_t & reply_callback = nullptr );
116
109
redis_client& client_getname (const reply_callback_t & reply_callback = nullptr );
117
110
redis_client& client_pause (int timeout, const reply_callback_t & reply_callback = nullptr );
@@ -319,31 +312,101 @@ class redis_client {
319
312
// redis_client& hscan(const reply_callback_t& reply_callback = nullptr) key cursor [match pattern] [count count]
320
313
// redis_client& zscan(const reply_callback_t& reply_callback = nullptr) key cursor [match pattern] [count count]
321
314
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
+
322
359
private:
323
- // ! client kill impl
360
+ // ! client kill internal impl
324
361
template <typename T>
325
362
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
+ }
327
376
328
377
template <typename T>
329
378
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
+ }
331
383
332
384
template <typename T>
333
385
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
+ }
335
390
336
391
template <typename T>
337
392
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
+ }
339
396
340
397
template <typename T, typename ... Ts>
341
398
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
+ };
343
404
344
405
template <typename T>
345
406
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
+ };
347
410
348
411
private:
349
412
// ! receive & disconnection handlers
@@ -376,5 +439,3 @@ class redis_client {
376
439
};
377
440
378
441
} // namespace cpp_redis
379
-
380
- #include < cpp_redis/impl/redis_client.ipp>
0 commit comments