cpp_redis  4.0.0
cpp_redis is a C++11 Asynchronous Multi-Platform Lightweight Redis Client, with support for synchronous operations and pipelining.
client.hpp
Go to the documentation of this file.
1 // The MIT License (MIT)
2 //
3 // Copyright (c) 2015-2017 Simon Ninon <simon.ninon@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to deal
7 // in the Software without restriction, including without limitation the rights
8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 // copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in all
13 // copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 // SOFTWARE.
22 
23 #pragma once
24 
25 #include <atomic>
26 #include <condition_variable>
27 #include <functional>
28 #include <future>
29 #include <map>
30 #include <mutex>
31 #include <queue>
32 #include <string>
33 #include <vector>
34 
40 
41 namespace cpp_redis {
42 
43 class client {
44 public:
49  enum class client_type {
50  normal,
51  master,
52  pubsub,
53  slave
54  };
55 
66  enum class connect_state {
67  dropped,
68  start,
69  sleeping,
70  ok,
71  failed,
72  lookup_failed,
73  stopped
74  };
75 
76 public:
77 #ifndef __CPP_REDIS_USE_CUSTOM_TCP_CLIENT
78  client(void);
80 #endif /* __CPP_REDIS_USE_CUSTOM_TCP_CLIENT */
81 
87  explicit client(const std::shared_ptr<network::tcp_client_iface>& tcp_client);
88 
90  ~client(void);
91 
93  client(const client&) = delete;
95  client& operator=(const client&) = delete;
96 
97 public:
101  typedef std::function<void(const std::string& host, std::size_t port, connect_state status)> connect_callback_t;
102 
113  void connect(
114  const std::string& host = "127.0.0.1",
115  std::size_t port = 6379,
116  const connect_callback_t& connect_callback = nullptr,
117  std::uint32_t timeout_msecs = 0,
118  std::int32_t max_reconnects = 0,
119  std::uint32_t reconnect_interval_msecs = 0);
120 
130  void connect(
131  const std::string& name,
132  const connect_callback_t& connect_callback = nullptr,
133  std::uint32_t timeout_msecs = 0,
134  std::int32_t max_reconnects = 0,
135  std::uint32_t reconnect_interval_msecs = 0);
136 
140  bool is_connected(void) const;
141 
147  void disconnect(bool wait_for_removal = false);
148 
152  bool is_reconnecting(void) const;
153 
157  void cancel_reconnect(void);
158 
159 public:
164  typedef std::function<void(reply&)> reply_callback_t;
165 
175  client& send(const std::vector<std::string>& redis_cmd, const reply_callback_t& callback);
176 
184  std::future<reply> send(const std::vector<std::string>& redis_cmd);
185 
194  client& commit(void);
195 
202  client& sync_commit(void);
203 
210  template <class Rep, class Period>
211  client&
212  sync_commit(const std::chrono::duration<Rep, Period>& timeout) {
215  if (!is_reconnecting()) {
216  try_commit();
217  }
218 
219  std::unique_lock<std::mutex> lock_callback(m_callbacks_mutex);
220  __CPP_REDIS_LOG(debug, "cpp_redis::client waiting for callbacks to complete");
221  if (!m_sync_condvar.wait_for(lock_callback, timeout, [=] { return m_callbacks_running == 0 && m_commands.empty(); })) {
222  __CPP_REDIS_LOG(debug, "cpp_redis::client finished waiting for callback");
223  }
224  else {
225  __CPP_REDIS_LOG(debug, "cpp_redis::client timed out waiting for callback");
226  }
227 
228  return *this;
229  }
230 
231 private:
235  bool should_reconnect(void) const;
236 
240  void resend_failed_commands(void);
241 
246 
251  void reconnect(void);
252 
256  void re_auth(void);
257 
261  void re_select(void);
262 
263 private:
271  void unprotected_send(const std::vector<std::string>& redis_cmd, const reply_callback_t& callback);
272 
280  void unprotected_auth(const std::string& password, const reply_callback_t& reply_callback);
281 
289  void unprotected_select(int index, const reply_callback_t& reply_callback);
290 
291 public:
298  void add_sentinel(const std::string& host, std::size_t port);
299 
305  const sentinel& get_sentinel(void) const;
306 
313  sentinel& get_sentinel(void);
314 
318  void clear_sentinels(void);
319 
320 public:
321  client& append(const std::string& key, const std::string& value, const reply_callback_t& reply_callback);
322  std::future<reply> append(const std::string& key, const std::string& value);
323 
324  client& auth(const std::string& password, const reply_callback_t& reply_callback);
325  std::future<reply> auth(const std::string& password);
326 
327  client& bgrewriteaof(const reply_callback_t& reply_callback);
328  std::future<reply> bgrewriteaof();
329 
330  client& bgsave(const reply_callback_t& reply_callback);
331  std::future<reply> bgsave();
332 
333  client& bitcount(const std::string& key, const reply_callback_t& reply_callback);
334  std::future<reply> bitcount(const std::string& key);
335 
336  client& bitcount(const std::string& key, int start, int end, const reply_callback_t& reply_callback);
337  std::future<reply> bitcount(const std::string& key, int start, int end);
338 
339  client& bitop(const std::string& operation, const std::string& destkey, const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
340  std::future<reply> bitop(const std::string& operation, const std::string& destkey, const std::vector<std::string>& keys);
341 
342  client& bitpos(const std::string& key, int bit, const reply_callback_t& reply_callback);
343  std::future<reply> bitpos(const std::string& key, int bit);
344 
345  client& bitpos(const std::string& key, int bit, int start, const reply_callback_t& reply_callback);
346  std::future<reply> bitpos(const std::string& key, int bit, int start);
347 
348  client& bitpos(const std::string& key, int bit, int start, int end, const reply_callback_t& reply_callback);
349  std::future<reply> bitpos(const std::string& key, int bit, int start, int end);
350 
351  client& blpop(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback);
352  std::future<reply> blpop(const std::vector<std::string>& keys, int timeout);
353 
354  client& brpop(const std::vector<std::string>& keys, int timeout, const reply_callback_t& reply_callback);
355  std::future<reply> brpop(const std::vector<std::string>& keys, int timeout);
356 
357  client& brpoplpush(const std::string& src, const std::string& dst, int timeout, const reply_callback_t& reply_callback);
358  std::future<reply> brpoplpush(const std::string& src, const std::string& dst, int timeout);
359 
360  template <typename T, typename... Ts>
361  client& client_kill(const std::string& host, int port, const T& arg, const Ts&... args);
362  client& client_kill(const std::string& host, int port);
363  template <typename... Ts>
364  client& client_kill(const char* host, int port, const Ts&... args);
365  template <typename T, typename... Ts>
366  client& client_kill(const T&, const Ts&...);
367  template <typename T, typename... Ts>
368  std::future<reply> client_kill_future(const T, const Ts...);
369 
370  client& client_list(const reply_callback_t& reply_callback);
371  std::future<reply> client_list();
372 
373  client& client_getname(const reply_callback_t& reply_callback);
374  std::future<reply> client_getname();
375 
376  client& client_pause(int timeout, const reply_callback_t& reply_callback);
377  std::future<reply> client_pause(int timeout);
378 
379  client& client_reply(const std::string& mode, const reply_callback_t& reply_callback);
380  std::future<reply> client_reply(const std::string& mode);
381 
382  client& client_setname(const std::string& name, const reply_callback_t& reply_callback);
383  std::future<reply> client_setname(const std::string& name);
384 
385  client& cluster_addslots(const std::vector<std::string>& p_slots, const reply_callback_t& reply_callback);
386  std::future<reply> cluster_addslots(const std::vector<std::string>& p_slots);
387 
388  client& cluster_count_failure_reports(const std::string& node_id, const reply_callback_t& reply_callback);
389  std::future<reply> cluster_count_failure_reports(const std::string& node_id);
390 
391  client& cluster_countkeysinslot(const std::string& slot, const reply_callback_t& reply_callback);
392  std::future<reply> cluster_countkeysinslot(const std::string& slot);
393 
394  client& cluster_delslots(const std::vector<std::string>& p_slots, const reply_callback_t& reply_callback);
395  std::future<reply> cluster_delslots(const std::vector<std::string>& p_slots);
396 
397  client& cluster_failover(const reply_callback_t& reply_callback);
398  std::future<reply> cluster_failover();
399 
400  client& cluster_failover(const std::string& mode, const reply_callback_t& reply_callback);
401  std::future<reply> cluster_failover(const std::string& mode);
402 
403  client& cluster_forget(const std::string& node_id, const reply_callback_t& reply_callback);
404  std::future<reply> cluster_forget(const std::string& node_id);
405 
406  client& cluster_getkeysinslot(const std::string& slot, int count, const reply_callback_t& reply_callback);
407  std::future<reply> cluster_getkeysinslot(const std::string& slot, int count);
408 
409  client& cluster_info(const reply_callback_t& reply_callback);
410  std::future<reply> cluster_info();
411 
412  client& cluster_keyslot(const std::string& key, const reply_callback_t& reply_callback);
413  std::future<reply> cluster_keyslot(const std::string& key);
414 
415  client& cluster_meet(const std::string& ip, int port, const reply_callback_t& reply_callback);
416  std::future<reply> cluster_meet(const std::string& ip, int port);
417 
418  client& cluster_nodes(const reply_callback_t& reply_callback);
419  std::future<reply> cluster_nodes();
420 
421  client& cluster_replicate(const std::string& node_id, const reply_callback_t& reply_callback);
422  std::future<reply> cluster_replicate(const std::string& node_id);
423 
424  client& cluster_reset(const reply_callback_t& reply_callback);
425  client& cluster_reset(const std::string& mode, const reply_callback_t& reply_callback);
426  std::future<reply> cluster_reset(const std::string& mode = "soft");
427 
428  client& cluster_saveconfig(const reply_callback_t& reply_callback);
429  std::future<reply> cluster_saveconfig();
430 
431  client& cluster_set_config_epoch(const std::string& epoch, const reply_callback_t& reply_callback);
432  std::future<reply> cluster_set_config_epoch(const std::string& epoch);
433 
434  client& cluster_setslot(const std::string& slot, const std::string& mode, const reply_callback_t& reply_callback);
435  std::future<reply> cluster_setslot(const std::string& slot, const std::string& mode);
436 
437  client& cluster_setslot(const std::string& slot, const std::string& mode, const std::string& node_id, const reply_callback_t& reply_callback);
438  std::future<reply> cluster_setslot(const std::string& slot, const std::string& mode, const std::string& node_id);
439 
440  client& cluster_slaves(const std::string& node_id, const reply_callback_t& reply_callback);
441  std::future<reply> cluster_slaves(const std::string& node_id);
442 
443  client& cluster_slots(const reply_callback_t& reply_callback);
444  std::future<reply> cluster_slots();
445 
446  client& command(const reply_callback_t& reply_callback);
447  std::future<reply> command();
448 
449  client& command_count(const reply_callback_t& reply_callback);
450  std::future<reply> command_count();
451 
452  client& command_getkeys(const reply_callback_t& reply_callback);
453  std::future<reply> command_getkeys();
454 
455  client& command_info(const std::vector<std::string>& command_name, const reply_callback_t& reply_callback);
456  std::future<reply> command_info(const std::vector<std::string>& command_name);
457 
458  client& config_get(const std::string& param, const reply_callback_t& reply_callback);
459  std::future<reply> config_get(const std::string& param);
460 
461  client& config_rewrite(const reply_callback_t& reply_callback);
462  std::future<reply> config_rewrite();
463 
464  client& config_set(const std::string& param, const std::string& val, const reply_callback_t& reply_callback);
465  std::future<reply> config_set(const std::string& param, const std::string& val);
466 
467  client& config_resetstat(const reply_callback_t& reply_callback);
468  std::future<reply> config_resetstat();
469 
470  client& dbsize(const reply_callback_t& reply_callback);
471  std::future<reply> dbsize();
472 
473  client& debug_object(const std::string& key, const reply_callback_t& reply_callback);
474  std::future<reply> debug_object(const std::string& key);
475 
476  client& debug_segfault(const reply_callback_t& reply_callback);
477  std::future<reply> debug_segfault();
478 
479  client& decr(const std::string& key, const reply_callback_t& reply_callback);
480  std::future<reply> decr(const std::string& key);
481 
482  client& decrby(const std::string& key, int val, const reply_callback_t& reply_callback);
483  std::future<reply> decrby(const std::string& key, int val);
484 
485  client& del(const std::vector<std::string>& key, const reply_callback_t& reply_callback);
486  std::future<reply> del(const std::vector<std::string>& key);
487 
488  client& discard(const reply_callback_t& reply_callback);
489  std::future<reply> discard();
490 
491  client& dump(const std::string& key, const reply_callback_t& reply_callback);
492  std::future<reply> dump(const std::string& key);
493 
494  client& echo(const std::string& msg, const reply_callback_t& reply_callback);
495  std::future<reply> echo(const std::string& msg);
496 
497  client& eval(const std::string& script, int numkeys, const std::vector<std::string>& keys, const std::vector<std::string>& args, const reply_callback_t& reply_callback);
498  std::future<reply> eval(const std::string& script, int numkeys, const std::vector<std::string>& keys, const std::vector<std::string>& args);
499 
500  client& evalsha(const std::string& sha1, int numkeys, const std::vector<std::string>& keys, const std::vector<std::string>& args, const reply_callback_t& reply_callback);
501  std::future<reply> evalsha(const std::string& sha1, int numkeys, const std::vector<std::string>& keys, const std::vector<std::string>& args);
502 
503  client& exec(const reply_callback_t& reply_callback);
504  std::future<reply> exec();
505 
506  client& exists(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
507  std::future<reply> exists(const std::vector<std::string>& keys);
508 
509  client& expire(const std::string& key, int seconds, const reply_callback_t& reply_callback);
510  std::future<reply> expire(const std::string& key, int seconds);
511 
512  client& expireat(const std::string& key, int timestamp, const reply_callback_t& reply_callback);
513  std::future<reply> expireat(const std::string& key, int timestamp);
514 
515  client& flushall(const reply_callback_t& reply_callback);
516  std::future<reply> flushall();
517 
518  client& flushdb(const reply_callback_t& reply_callback);
519  std::future<reply> flushdb();
520 
521  client& geoadd(const std::string& key, const std::vector<std::tuple<std::string, std::string, std::string>>& long_lat_memb, const reply_callback_t& reply_callback);
522  std::future<reply> geoadd(const std::string& key, const std::vector<std::tuple<std::string, std::string, std::string>>& long_lat_memb);
523 
524  client& geohash(const std::string& key, const std::vector<std::string>& members, const reply_callback_t& reply_callback);
525  std::future<reply> geohash(const std::string& key, const std::vector<std::string>& members);
526 
527  client& geopos(const std::string& key, const std::vector<std::string>& members, const reply_callback_t& reply_callback);
528  std::future<reply> geopos(const std::string& key, const std::vector<std::string>& members);
529 
530  client& geodist(const std::string& key, const std::string& member_1, const std::string& member_2, const reply_callback_t& reply_callback);
531  client& geodist(const std::string& key, const std::string& member_1, const std::string& member_2, const std::string& unit, const reply_callback_t& reply_callback);
532  std::future<reply> geodist(const std::string& key, const std::string& member_1, const std::string& member_2, const std::string& unit = "m");
533 
534  client& get(const std::string& key, const reply_callback_t& reply_callback);
535  std::future<reply> get(const std::string& key);
536 
537  client& getbit(const std::string& key, int offset, const reply_callback_t& reply_callback);
538  std::future<reply> getbit(const std::string& key, int offset);
539 
540  client& getrange(const std::string& key, int start, int end, const reply_callback_t& reply_callback);
541  std::future<reply> getrange(const std::string& key, int start, int end);
542 
543  client& getset(const std::string& key, const std::string& val, const reply_callback_t& reply_callback);
544  std::future<reply> getset(const std::string& key, const std::string& val);
545 
546  client& hdel(const std::string& key, const std::vector<std::string>& fields, const reply_callback_t& reply_callback);
547  std::future<reply> hdel(const std::string& key, const std::vector<std::string>& fields);
548 
549  client& hexists(const std::string& key, const std::string& field, const reply_callback_t& reply_callback);
550  std::future<reply> hexists(const std::string& key, const std::string& field);
551 
552  client& hget(const std::string& key, const std::string& field, const reply_callback_t& reply_callback);
553  std::future<reply> hget(const std::string& key, const std::string& field);
554 
555  client& hgetall(const std::string& key, const reply_callback_t& reply_callback);
556  std::future<reply> hgetall(const std::string& key);
557 
558  client& hincrby(const std::string& key, const std::string& field, int incr, const reply_callback_t& reply_callback);
559  std::future<reply> hincrby(const std::string& key, const std::string& field, int incr);
560 
561  client& hincrbyfloat(const std::string& key, const std::string& field, float incr, const reply_callback_t& reply_callback);
562  std::future<reply> hincrbyfloat(const std::string& key, const std::string& field, float incr);
563 
564  client& hkeys(const std::string& key, const reply_callback_t& reply_callback);
565  std::future<reply> hkeys(const std::string& key);
566 
567  client& hlen(const std::string& key, const reply_callback_t& reply_callback);
568  std::future<reply> hlen(const std::string& key);
569 
570  client& hmget(const std::string& key, const std::vector<std::string>& fields, const reply_callback_t& reply_callback);
571  std::future<reply> hmget(const std::string& key, const std::vector<std::string>& fields);
572 
573  client& hmset(const std::string& key, const std::vector<std::pair<std::string, std::string>>& field_val, const reply_callback_t& reply_callback);
574  std::future<reply> hmset(const std::string& key, const std::vector<std::pair<std::string, std::string>>& field_val);
575 
576  client& hset(const std::string& key, const std::string& field, const std::string& value, const reply_callback_t& reply_callback);
577  std::future<reply> hset(const std::string& key, const std::string& field, const std::string& value);
578 
579  client& hsetnx(const std::string& key, const std::string& field, const std::string& value, const reply_callback_t& reply_callback);
580  std::future<reply> hsetnx(const std::string& key, const std::string& field, const std::string& value);
581 
582  client& hstrlen(const std::string& key, const std::string& field, const reply_callback_t& reply_callback);
583  std::future<reply> hstrlen(const std::string& key, const std::string& field);
584 
585  client& hvals(const std::string& key, const reply_callback_t& reply_callback);
586  std::future<reply> hvals(const std::string& key);
587 
588  client& incr(const std::string& key, const reply_callback_t& reply_callback);
589  std::future<reply> incr(const std::string& key);
590 
591  client& incrby(const std::string& key, int incr, const reply_callback_t& reply_callback);
592  std::future<reply> incrby(const std::string& key, int incr);
593 
594  client& incrbyfloat(const std::string& key, float incr, const reply_callback_t& reply_callback);
595  std::future<reply> incrbyfloat(const std::string& key, float incr);
596 
597  client& info(const reply_callback_t& reply_callback);
598  client& info(const std::string& section, const reply_callback_t& reply_callback);
599  std::future<reply> info(const std::string& section = "default");
600 
601  client& keys(const std::string& pattern, const reply_callback_t& reply_callback);
602  std::future<reply> keys(const std::string& pattern);
603 
604  client& lastsave(const reply_callback_t& reply_callback);
605  std::future<reply> lastsave();
606 
607  client& lindex(const std::string& key, int index, const reply_callback_t& reply_callback);
608  std::future<reply> lindex(const std::string& key, int index);
609 
610  client& linsert(const std::string& key, const std::string& before_after, const std::string& pivot, const std::string& value, const reply_callback_t& reply_callback);
611  std::future<reply> linsert(const std::string& key, const std::string& before_after, const std::string& pivot, const std::string& value);
612 
613  client& llen(const std::string& key, const reply_callback_t& reply_callback);
614  std::future<reply> llen(const std::string& key);
615 
616  client& lpop(const std::string& key, const reply_callback_t& reply_callback);
617  std::future<reply> lpop(const std::string& key);
618 
619  client& lpush(const std::string& key, const std::vector<std::string>& values, const reply_callback_t& reply_callback);
620  std::future<reply> lpush(const std::string& key, const std::vector<std::string>& values);
621 
622  client& lpushx(const std::string& key, const std::string& value, const reply_callback_t& reply_callback);
623  std::future<reply> lpushx(const std::string& key, const std::string& value);
624 
625  client& lrange(const std::string& key, int start, int stop, const reply_callback_t& reply_callback);
626  std::future<reply> lrange(const std::string& key, int start, int stop);
627 
628  client& lrem(const std::string& key, int count, const std::string& value, const reply_callback_t& reply_callback);
629  std::future<reply> lrem(const std::string& key, int count, const std::string& value);
630 
631  client& lset(const std::string& key, int index, const std::string& value, const reply_callback_t& reply_callback);
632  std::future<reply> lset(const std::string& key, int index, const std::string& value);
633 
634  client& ltrim(const std::string& key, int start, int stop, const reply_callback_t& reply_callback);
635  std::future<reply> ltrim(const std::string& key, int start, int stop);
636 
637  client& mget(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
638  std::future<reply> mget(const std::vector<std::string>& keys);
639 
640  client& migrate(const std::string& host, int port, const std::string& key, const std::string& dest_db, int timeout, const reply_callback_t& reply_callback);
641  client& migrate(const std::string& host, int port, const std::string& key, const std::string& dest_db, int timeout, bool copy, bool replace, const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
642  std::future<reply> migrate(const std::string& host, int port, const std::string& key, const std::string& dest_db, int timeout, bool copy = false, bool replace = false, const std::vector<std::string>& keys = {});
643 
644  client& monitor(const reply_callback_t& reply_callback);
645  std::future<reply> monitor();
646 
647  client& move(const std::string& key, const std::string& db, const reply_callback_t& reply_callback);
648  std::future<reply> move(const std::string& key, const std::string& db);
649 
650  client& mset(const std::vector<std::pair<std::string, std::string>>& key_vals, const reply_callback_t& reply_callback);
651  std::future<reply> mset(const std::vector<std::pair<std::string, std::string>>& key_vals);
652 
653  client& msetnx(const std::vector<std::pair<std::string, std::string>>& key_vals, const reply_callback_t& reply_callback);
654  std::future<reply> msetnx(const std::vector<std::pair<std::string, std::string>>& key_vals);
655 
656  client& multi(const reply_callback_t& reply_callback);
657  std::future<reply> multi();
658 
659  client& object(const std::string& subcommand, const std::vector<std::string>& args, const reply_callback_t& reply_callback);
660  std::future<reply> object(const std::string& subcommand, const std::vector<std::string>& args);
661 
662  client& persist(const std::string& key, const reply_callback_t& reply_callback);
663  std::future<reply> persist(const std::string& key);
664 
665  client& pexpire(const std::string& key, int milliseconds, const reply_callback_t& reply_callback);
666  std::future<reply> pexpire(const std::string& key, int milliseconds);
667 
668  client& pexpireat(const std::string& key, int milliseconds_timestamp, const reply_callback_t& reply_callback);
669  std::future<reply> pexpireat(const std::string& key, int milliseconds_timestamp);
670 
671  client& pfadd(const std::string& key, const std::vector<std::string>& elements, const reply_callback_t& reply_callback);
672  std::future<reply> pfadd(const std::string& key, const std::vector<std::string>& elements);
673 
674  client& pfcount(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
675  std::future<reply> pfcount(const std::vector<std::string>& keys);
676 
677  client& pfmerge(const std::string& destkey, const std::vector<std::string>& sourcekeys, const reply_callback_t& reply_callback);
678  std::future<reply> pfmerge(const std::string& destkey, const std::vector<std::string>& sourcekeys);
679 
680  client& ping(const reply_callback_t& reply_callback);
681  std::future<reply> ping();
682 
683  client& ping(const std::string& message, const reply_callback_t& reply_callback);
684  std::future<reply> ping(const std::string& message);
685 
686  client& psetex(const std::string& key, int milliseconds, const std::string& val, const reply_callback_t& reply_callback);
687  std::future<reply> psetex(const std::string& key, int milliseconds, const std::string& val);
688 
689  client& publish(const std::string& channel, const std::string& message, const reply_callback_t& reply_callback);
690  std::future<reply> publish(const std::string& channel, const std::string& message);
691 
692  client& pubsub(const std::string& subcommand, const std::vector<std::string>& args, const reply_callback_t& reply_callback);
693  std::future<reply> pubsub(const std::string& subcommand, const std::vector<std::string>& args);
694 
695  client& pttl(const std::string& key, const reply_callback_t& reply_callback);
696  std::future<reply> pttl(const std::string& key);
697 
698  client& quit(const reply_callback_t& reply_callback);
699  std::future<reply> quit();
700 
701  client& randomkey(const reply_callback_t& reply_callback);
702  std::future<reply> randomkey();
703 
704  client& readonly(const reply_callback_t& reply_callback);
705  std::future<reply> readonly();
706 
707  client& readwrite(const reply_callback_t& reply_callback);
708  std::future<reply> readwrite();
709 
710  client& rename(const std::string& key, const std::string& newkey, const reply_callback_t& reply_callback);
711  std::future<reply> rename(const std::string& key, const std::string& newkey);
712 
713  client& renamenx(const std::string& key, const std::string& newkey, const reply_callback_t& reply_callback);
714  std::future<reply> renamenx(const std::string& key, const std::string& newkey);
715 
716  client& restore(const std::string& key, int ttl, const std::string& serialized_value, const reply_callback_t& reply_callback);
717  std::future<reply> restore(const std::string& key, int ttl, const std::string& serialized_value);
718 
719  client& restore(const std::string& key, int ttl, const std::string& serialized_value, const std::string& replace, const reply_callback_t& reply_callback);
720  std::future<reply> restore(const std::string& key, int ttl, const std::string& serialized_value, const std::string& replace);
721 
722  client& role(const reply_callback_t& reply_callback);
723  std::future<reply> role();
724 
725  client& rpop(const std::string& key, const reply_callback_t& reply_callback);
726  std::future<reply> rpop(const std::string& key);
727 
728  client& rpoplpush(const std::string& source, const std::string& destination, const reply_callback_t& reply_callback);
729  std::future<reply> rpoplpush(const std::string& src, const std::string& dst);
730 
731  client& rpush(const std::string& key, const std::vector<std::string>& values, const reply_callback_t& reply_callback);
732  std::future<reply> rpush(const std::string& key, const std::vector<std::string>& values);
733 
734  client& rpushx(const std::string& key, const std::string& value, const reply_callback_t& reply_callback);
735  std::future<reply> rpushx(const std::string& key, const std::string& value);
736 
737  client& sadd(const std::string& key, const std::vector<std::string>& members, const reply_callback_t& reply_callback);
738  std::future<reply> sadd(const std::string& key, const std::vector<std::string>& members);
739 
740  client& save(const reply_callback_t& reply_callback);
741  std::future<reply> save();
742 
743  client& scan(int cursor, const std::string& pattern, int count, const reply_callback_t& reply_callback);
744  std::future<reply> scan(int cursor, const std::string& pattern, int count);
745 
746  client& scard(const std::string& key, const reply_callback_t& reply_callback);
747  std::future<reply> scard(const std::string& key);
748 
749  client& script_debug(const std::string& mode, const reply_callback_t& reply_callback);
750  std::future<reply> script_debug(const std::string& mode);
751 
752  client& script_exists(const std::vector<std::string>& scripts, const reply_callback_t& reply_callback);
753  std::future<reply> script_exists(const std::vector<std::string>& scripts);
754 
755  client& script_flush(const reply_callback_t& reply_callback);
756  std::future<reply> script_flush();
757 
758  client& script_kill(const reply_callback_t& reply_callback);
759  std::future<reply> script_kill();
760 
761  client& script_load(const std::string& script, const reply_callback_t& reply_callback);
762  std::future<reply> script_load(const std::string& script);
763 
764  client& sdiff(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
765  std::future<reply> sdiff(const std::vector<std::string>& keys);
766 
767  client& sdiffstore(const std::string& destination, const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
768  std::future<reply> sdiffstore(const std::string& dst, const std::vector<std::string>& keys);
769 
770  client& select(int index, const reply_callback_t& reply_callback);
771  std::future<reply> select(int index);
772 
773  client& set(const std::string& key, const std::string& value, const reply_callback_t& reply_callback);
774  std::future<reply> set(const std::string& key, const std::string& value);
775 
776  client& set_advanced(const std::string& key, const std::string& value, const reply_callback_t& reply_callback);
777  client& set_advanced(const std::string& key, const std::string& value, bool ex, int ex_sec, bool px, int px_milli, bool nx, bool xx, const reply_callback_t& reply_callback);
778  std::future<reply> set_advanced(const std::string& key, const std::string& value, bool ex = false, int ex_sec = 0, bool px = false, int px_milli = 0, bool nx = false, bool xx = false);
779 
780  client& setbit_(const std::string& key, int offset, const std::string& value, const reply_callback_t& reply_callback);
781  std::future<reply> setbit_(const std::string& key, int offset, const std::string& value);
782 
783  client& setex(const std::string& key, int seconds, const std::string& value, const reply_callback_t& reply_callback);
784  std::future<reply> setex(const std::string& key, int seconds, const std::string& value);
785 
786  client& setnx(const std::string& key, const std::string& value, const reply_callback_t& reply_callback);
787  std::future<reply> setnx(const std::string& key, const std::string& value);
788 
789  client& setrange(const std::string& key, int offset, const std::string& value, const reply_callback_t& reply_callback);
790  std::future<reply> setrange(const std::string& key, int offset, const std::string& value);
791 
792  client& shutdown(const reply_callback_t& reply_callback);
793  std::future<reply> shutdown();
794 
795  client& shutdown(const std::string& save, const reply_callback_t& reply_callback);
796  std::future<reply> shutdown(const std::string& save);
797 
798  client& sinter(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
799  std::future<reply> sinter(const std::vector<std::string>& keys);
800 
801  client& sinterstore(const std::string& destination, const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
802  std::future<reply> sinterstore(const std::string& dst, const std::vector<std::string>& keys);
803 
804  client& sismember(const std::string& key, const std::string& member, const reply_callback_t& reply_callback);
805  std::future<reply> sismember(const std::string& key, const std::string& member);
806 
807  client& slaveof(const std::string& host, int port, const reply_callback_t& reply_callback);
808  std::future<reply> slaveof(const std::string& host, int port);
809 
810  client& slowlog(const std::string subcommand, const reply_callback_t& reply_callback);
811  std::future<reply> slowlog(const std::string& subcommand);
812 
813  client& slowlog(const std::string subcommand, const std::string& argument, const reply_callback_t& reply_callback);
814  std::future<reply> slowlog(const std::string& subcommand, const std::string& argument);
815 
816  client& smembers(const std::string& key, const reply_callback_t& reply_callback);
817  std::future<reply> smembers(const std::string& key);
818 
819  client& smove(const std::string& source, const std::string& destination, const std::string& member, const reply_callback_t& reply_callback);
820  std::future<reply> smove(const std::string& src, const std::string& dst, const std::string& member);
821 
822  client& spop(const std::string& key, const reply_callback_t& reply_callback);
823  std::future<reply> spop(const std::string& key);
824 
825  client& spop(const std::string& key, int count, const reply_callback_t& reply_callback);
826  std::future<reply> spop(const std::string& key, int count);
827 
828  client& srandmember(const std::string& key, const reply_callback_t& reply_callback);
829  std::future<reply> srandmember(const std::string& key);
830 
831  client& srandmember(const std::string& key, int count, const reply_callback_t& reply_callback);
832  std::future<reply> srandmember(const std::string& key, int count);
833 
834  client& srem(const std::string& key, const std::vector<std::string>& members, const reply_callback_t& reply_callback);
835  std::future<reply> srem(const std::string& key, const std::vector<std::string>& members);
836 
837  client& strlen(const std::string& key, const reply_callback_t& reply_callback);
838  std::future<reply> strlen(const std::string& key);
839 
840  client& sunion(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
841  std::future<reply> sunion(const std::vector<std::string>& keys);
842 
843  client& sunionstore(const std::string& destination, const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
844  std::future<reply> sunionstore(const std::string& dst, const std::vector<std::string>& keys);
845 
846  client& sync(const reply_callback_t& reply_callback);
847  std::future<reply> sync();
848 
849  client& time(const reply_callback_t& reply_callback);
850  std::future<reply> time();
851 
852  client& ttl(const std::string& key, const reply_callback_t& reply_callback);
853  std::future<reply> ttl(const std::string& key);
854 
855  client& type(const std::string& key, const reply_callback_t& reply_callback);
856  std::future<reply> type(const std::string& key);
857 
858  client& unwatch(const reply_callback_t& reply_callback);
859  std::future<reply> unwatch();
860 
861  client& wait(int numslaves, int timeout, const reply_callback_t& reply_callback);
862  std::future<reply> wait(int numslaves, int timeout);
863 
864  client& watch(const std::vector<std::string>& keys, const reply_callback_t& reply_callback);
865  std::future<reply> watch(const std::vector<std::string>& keys);
866 
867  client& zadd(const std::string& key, const std::vector<std::string>& options, const std::map<std::string, std::string>& score_members, const reply_callback_t& reply_callback);
868  std::future<reply> zadd(const std::string& key, const std::vector<std::string>& options, const std::map<std::string, std::string>& score_members);
869 
870  client& zcard(const std::string& key, const reply_callback_t& reply_callback);
871  std::future<reply> zcard(const std::string& key);
872 
873  client& zcount(const std::string& key, int min, int max, const reply_callback_t& reply_callback);
874  std::future<reply> zcount(const std::string& key, int min, int max);
875 
876  client& zcount(const std::string& key, double min, double max, const reply_callback_t& reply_callback);
877  std::future<reply> zcount(const std::string& key, double min, double max);
878 
879  client& zcount(const std::string& key, const std::string& min, const std::string& max, const reply_callback_t& reply_callback);
880  std::future<reply> zcount(const std::string& key, const std::string& min, const std::string& max);
881 
882  client& zincrby(const std::string& key, int incr, const std::string& member, const reply_callback_t& reply_callback);
883  std::future<reply> zincrby(const std::string& key, int incr, const std::string& member);
884 
885  client& zincrby(const std::string& key, double incr, const std::string& member, const reply_callback_t& reply_callback);
886  std::future<reply> zincrby(const std::string& key, double incr, const std::string& member);
887 
888  client& zincrby(const std::string& key, const std::string& incr, const std::string& member, const reply_callback_t& reply_callback);
889  std::future<reply> zincrby(const std::string& key, const std::string& incr, const std::string& member);
890 
891  client& zlexcount(const std::string& key, int min, int max, const reply_callback_t& reply_callback);
892  std::future<reply> zlexcount(const std::string& key, int min, int max);
893 
894  client& zlexcount(const std::string& key, double min, double max, const reply_callback_t& reply_callback);
895  std::future<reply> zlexcount(const std::string& key, double min, double max);
896 
897  client& zlexcount(const std::string& key, const std::string& min, const std::string& max, const reply_callback_t& reply_callback);
898  std::future<reply> zlexcount(const std::string& key, const std::string& min, const std::string& max);
899 
900  client& zrange(const std::string& key, int start, int stop, const reply_callback_t& reply_callback);
901  client& zrange(const std::string& key, int start, int stop, bool withscores, const reply_callback_t& reply_callback);
902  std::future<reply> zrange(const std::string& key, int start, int stop, bool withscores = false);
903 
904  client& zrange(const std::string& key, double start, double stop, const reply_callback_t& reply_callback);
905  client& zrange(const std::string& key, double start, double stop, bool withscores, const reply_callback_t& reply_callback);
906  std::future<reply> zrange(const std::string& key, double start, double stop, bool withscores = false);
907 
908  client& zrange(const std::string& key, const std::string& start, const std::string& stop, const reply_callback_t& reply_callback);
909  client& zrange(const std::string& key, const std::string& start, const std::string& stop, bool withscores, const reply_callback_t& reply_callback);
910  std::future<reply> zrange(const std::string& key, const std::string& start, const std::string& stop, bool withscores = false);
911 
912  client& zrank(const std::string& key, const std::string& member, const reply_callback_t& reply_callback);
913  std::future<reply> zrank(const std::string& key, const std::string& member);
914 
915  client& zrem(const std::string& key, const std::vector<std::string>& members, const reply_callback_t& reply_callback);
916  std::future<reply> zrem(const std::string& key, const std::vector<std::string>& members);
917 
918  client& zremrangebylex(const std::string& key, int min, int max, const reply_callback_t& reply_callback);
919  std::future<reply> zremrangebylex(const std::string& key, int min, int max);
920 
921  client& zremrangebylex(const std::string& key, double min, double max, const reply_callback_t& reply_callback);
922  std::future<reply> zremrangebylex(const std::string& key, double min, double max);
923 
924  client& zremrangebylex(const std::string& key, const std::string& min, const std::string& max, const reply_callback_t& reply_callback);
925  std::future<reply> zremrangebylex(const std::string& key, const std::string& min, const std::string& max);
926 
927  client& zremrangebyrank(const std::string& key, int start, int stop, const reply_callback_t& reply_callback);
928  std::future<reply> zremrangebyrank(const std::string& key, int start, int stop);
929 
930  client& zremrangebyrank(const std::string& key, double start, double stop, const reply_callback_t& reply_callback);
931  std::future<reply> zremrangebyrank(const std::string& key, double start, double stop);
932 
933  client& zremrangebyrank(const std::string& key, const std::string& start, const std::string& stop, const reply_callback_t& reply_callback);
934  std::future<reply> zremrangebyrank(const std::string& key, const std::string& start, const std::string& stop);
935 
936  client& zremrangebyscore(const std::string& key, int min, int max, const reply_callback_t& reply_callback);
937  std::future<reply> zremrangebyscore(const std::string& key, int min, int max);
938 
939  client& zremrangebyscore(const std::string& key, double min, double max, const reply_callback_t& reply_callback);
940  std::future<reply> zremrangebyscore(const std::string& key, double min, double max);
941 
942  client& zremrangebyscore(const std::string& key, const std::string& min, const std::string& max, const reply_callback_t& reply_callback);
943  std::future<reply> zremrangebyscore(const std::string& key, const std::string& min, const std::string& max);
944 
945  client& zrevrange(const std::string& key, int start, int stop, const reply_callback_t& reply_callback);
946  client& zrevrange(const std::string& key, int start, int stop, bool withscores, const reply_callback_t& reply_callback);
947  std::future<reply> zrevrange(const std::string& key, int start, int stop, bool withscores = false);
948 
949  client& zrevrange(const std::string& key, double start, double stop, const reply_callback_t& reply_callback);
950  client& zrevrange(const std::string& key, double start, double stop, bool withscores, const reply_callback_t& reply_callback);
951  std::future<reply> zrevrange(const std::string& key, double start, double stop, bool withscores = false);
952 
953  client& zrevrange(const std::string& key, const std::string& start, const std::string& stop, const reply_callback_t& reply_callback);
954  client& zrevrange(const std::string& key, const std::string& start, const std::string& stop, bool withscores, const reply_callback_t& reply_callback);
955  std::future<reply> zrevrange(const std::string& key, const std::string& start, const std::string& stop, bool withscores = false);
956 
957  client& zrevrank(const std::string& key, const std::string& member, const reply_callback_t& reply_callback);
958  std::future<reply> zrevrank(const std::string& key, const std::string& member);
959 
960  client& zscore(const std::string& key, const std::string& member, const reply_callback_t& reply_callback);
961  std::future<reply> zscore(const std::string& key, const std::string& member);
962 
963  // client& bitfield(const std::string& key, const reply_callback_t& reply_callback) key [get type offset] [set type offset value] [incrby type offset increment] [overflow wrap|sat|fail]
964  // client& georadius(const reply_callback_t& reply_callback) key longitude latitude radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count] [asc|desc] [store key] [storedist key]
965  // client& georadiusbymember(const reply_callback_t& reply_callback) key member radius m|km|ft|mi [withcoord] [withdist] [withhash] [count count] [asc|desc] [store key] [storedist key]
966  // client& sort(const reply_callback_t& reply_callback) key [by pattern] [limit offset count] [get pattern [get pattern ...]] [asc|desc] [alpha] [store destination]
967  // client& zinterstore(const reply_callback_t& reply_callback) destination numkeys key [key ...] [weights weight [weight ...]] [aggregate sum|min|max]
968  // client& zrangebylex(const reply_callback_t& reply_callback) key min max [limit offset count]
969  // client& zrevrangebylex(const reply_callback_t& reply_callback) key max min [limit offset count]
970  // client& zrangebyscore(const reply_callback_t& reply_callback) key min max [withscores] [limit offset count]
971  // client& zrevrangebyscore(const reply_callback_t& reply_callback) key max min [withscores] [limit offset count]
972  // client& zunionstore(const reply_callback_t& reply_callback) destination numkeys key [key ...] [weights weight [weight ...]] [aggregate sum|min|max]
973  // client& sscan(const reply_callback_t& reply_callback) key cursor [match pattern] [count count]
974  // client& hscan(const reply_callback_t& reply_callback) key cursor [match pattern] [count count]
975  // client& zscan(const reply_callback_t& reply_callback) key cursor [match pattern] [count count]
976 
977 private:
979  template <typename T>
980  typename std::enable_if<std::is_same<T, client_type>::value>::type
981  client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, client_type type);
982 
983  template <typename T>
984  typename std::enable_if<std::is_same<T, bool>::value>::type
985  client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, bool skip);
986 
987  template <typename T>
988  typename std::enable_if<std::is_integral<T>::value>::type
989  client_kill_unpack_arg(std::vector<std::string>& redis_cmd, reply_callback_t&, uint64_t id);
990 
991  template <typename T>
992  typename std::enable_if<std::is_class<T>::value>::type
993  client_kill_unpack_arg(std::vector<std::string>&, reply_callback_t& reply_callback, const T& cb);
994 
995  template <typename T, typename... Ts>
996  void
997  client_kill_impl(std::vector<std::string>& redis_cmd, reply_callback_t& reply, const T& arg, const Ts&... args);
998 
999  template <typename T>
1000  void
1001  client_kill_impl(std::vector<std::string>& redis_cmd, reply_callback_t& reply, const T& arg);
1002 
1003 private:
1010  void connection_receive_handler(network::redis_connection& connection, reply& reply);
1011 
1018 
1022  void clear_callbacks(void);
1023 
1028  void try_commit(void);
1029 
1031  std::future<reply> exec_cmd(const std::function<client&(const reply_callback_t&)>& f);
1032 
1033 private:
1038  std::vector<std::string> command;
1039  reply_callback_t callback;
1040  };
1041 
1042 private:
1046  std::string m_redis_server;
1050  std::size_t m_redis_port = 0;
1054  std::string m_master_name;
1058  std::string m_password;
1063 
1068 
1073 
1077  std::uint32_t m_connect_timeout_msecs = 0;
1081  std::int32_t m_max_reconnects = 0;
1089  std::uint32_t m_reconnect_interval_msecs = 0;
1090 
1094  std::atomic_bool m_reconnecting = ATOMIC_VAR_INIT(false);
1098  std::atomic_bool m_cancel = ATOMIC_VAR_INIT(false);
1099 
1103  std::queue<command_request> m_commands;
1104 
1108  connect_callback_t m_connect_callback;
1109 
1113  std::mutex m_callbacks_mutex;
1114 
1118  std::condition_variable m_sync_condvar;
1119 
1123  std::atomic<unsigned int> m_callbacks_running = ATOMIC_VAR_INIT(0);
1124 }; // namespace cpp_redis
1125 
1126 } // namespace cpp_redis
1127 
1128 #include <cpp_redis/impl/client.ipp>
std::future< reply > script_kill()
std::atomic_bool m_cancel
Definition: client.hpp:1098
client & restore(const std::string &key, int ttl, const std::string &serialized_value, const reply_callback_t &reply_callback)
client & hstrlen(const std::string &key, const std::string &field, const reply_callback_t &reply_callback)
std::future< reply > sync()
std::uint32_t m_connect_timeout_msecs
Definition: client.hpp:1077
client & bitcount(const std::string &key, const reply_callback_t &reply_callback)
Definition: redis_connection.hpp:45
client & rpoplpush(const std::string &source, const std::string &destination, const reply_callback_t &reply_callback)
std::future< reply > ping()
std::future< reply > config_rewrite()
Definition: client.hpp:1037
client & sunion(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
client & scard(const std::string &key, const reply_callback_t &reply_callback)
client & set_advanced(const std::string &key, const std::string &value, const reply_callback_t &reply_callback)
client & publish(const std::string &channel, const std::string &message, const reply_callback_t &reply_callback)
client & config_get(const std::string &param, const reply_callback_t &reply_callback)
client & scan(int cursor, const std::string &pattern, int count, const reply_callback_t &reply_callback)
void unprotected_send(const std::vector< std::string > &redis_cmd, const reply_callback_t &callback)
client & msetnx(const std::vector< std::pair< std::string, std::string >> &key_vals, const reply_callback_t &reply_callback)
std::future< reply > client_kill_future(const T, const Ts...)
Definition: client.ipp:122
std::future< reply > cluster_failover()
std::future< reply > exec()
client(void)
ctor
client & getrange(const std::string &key, int start, int end, const reply_callback_t &reply_callback)
client & geodist(const std::string &key, const std::string &member_1, const std::string &member_2, const reply_callback_t &reply_callback)
void connection_receive_handler(network::redis_connection &connection, reply &reply)
Definition: client.hpp:43
client & cluster_setslot(const std::string &slot, const std::string &mode, const reply_callback_t &reply_callback)
client & geoadd(const std::string &key, const std::vector< std::tuple< std::string, std::string, std::string >> &long_lat_memb, const reply_callback_t &reply_callback)
std::future< reply > cluster_saveconfig()
client & zlexcount(const std::string &key, int min, int max, const reply_callback_t &reply_callback)
std::int32_t m_current_reconnect_attempts
Definition: client.hpp:1085
std::future< reply > command_count()
client & cluster_getkeysinslot(const std::string &slot, int count, const reply_callback_t &reply_callback)
std::future< reply > bgrewriteaof()
client & cluster_delslots(const std::vector< std::string > &p_slots, const reply_callback_t &reply_callback)
client & rpush(const std::string &key, const std::vector< std::string > &values, const reply_callback_t &reply_callback)
std::future< reply > command_getkeys()
client & getbit(const std::string &key, int offset, const reply_callback_t &reply_callback)
client & setnx(const std::string &key, const std::string &value, const reply_callback_t &reply_callback)
client & rpushx(const std::string &key, const std::string &value, const reply_callback_t &reply_callback)
client & brpop(const std::vector< std::string > &keys, int timeout, const reply_callback_t &reply_callback)
std::future< reply > readwrite()
std::string m_master_name
Definition: client.hpp:1054
client & blpop(const std::vector< std::string > &keys, int timeout, const reply_callback_t &reply_callback)
client & operator=(const client &)=delete
assignment operator
client & cluster_forget(const std::string &node_id, const reply_callback_t &reply_callback)
client & cluster_meet(const std::string &ip, int port, const reply_callback_t &reply_callback)
client & hdel(const std::string &key, const std::vector< std::string > &fields, const reply_callback_t &reply_callback)
connect_callback_t m_connect_callback
Definition: client.hpp:1108
std::future< reply > flushall()
std::future< reply > cluster_info()
client & lset(const std::string &key, int index, const std::string &value, const reply_callback_t &reply_callback)
client & zincrby(const std::string &key, int incr, const std::string &member, const reply_callback_t &reply_callback)
client & smembers(const std::string &key, const reply_callback_t &reply_callback)
client & setbit_(const std::string &key, int offset, const std::string &value, const reply_callback_t &reply_callback)
void sleep_before_next_reconnect_attempt(void)
client & client_setname(const std::string &name, const reply_callback_t &reply_callback)
std::future< reply > exec_cmd(const std::function< client &(const reply_callback_t &)> &f)
Execute a command on the client and tie the callback to a future.
client & exists(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
std::future< reply > debug_segfault()
client & hexists(const std::string &key, const std::string &field, const reply_callback_t &reply_callback)
void re_select(void)
client & select(int index, const reply_callback_t &reply_callback)
client & zremrangebyscore(const std::string &key, int min, int max, const reply_callback_t &reply_callback)
client & lindex(const std::string &key, int index, const reply_callback_t &reply_callback)
std::future< reply > command()
client & hset(const std::string &key, const std::string &field, const std::string &value, const reply_callback_t &reply_callback)
client & brpoplpush(const std::string &src, const std::string &dst, int timeout, const reply_callback_t &reply_callback)
client & zremrangebylex(const std::string &key, int min, int max, const reply_callback_t &reply_callback)
void cancel_reconnect(void)
client & sinter(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
client & object(const std::string &subcommand, const std::vector< std::string > &args, const reply_callback_t &reply_callback)
std::future< reply > unwatch()
client & sadd(const std::string &key, const std::vector< std::string > &members, const reply_callback_t &reply_callback)
client & pttl(const std::string &key, const reply_callback_t &reply_callback)
client & hget(const std::string &key, const std::string &field, const reply_callback_t &reply_callback)
client & pexpire(const std::string &key, int milliseconds, const reply_callback_t &reply_callback)
client & llen(const std::string &key, const reply_callback_t &reply_callback)
client & cluster_countkeysinslot(const std::string &slot, const reply_callback_t &reply_callback)
std::future< reply > save()
client & srandmember(const std::string &key, const reply_callback_t &reply_callback)
std::uint32_t m_reconnect_interval_msecs
Definition: client.hpp:1089
client & spop(const std::string &key, const reply_callback_t &reply_callback)
reply_callback_t callback
Definition: client.hpp:1039
client & client_kill(const std::string &host, int port, const T &arg, const Ts &... args)
Definition: client.ipp:93
Definition: reply.hpp:33
client & zremrangebyrank(const std::string &key, int start, int stop, const reply_callback_t &reply_callback)
int m_database_index
Definition: client.hpp:1062
client & sunionstore(const std::string &destination, const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
client & sismember(const std::string &key, const std::string &member, const reply_callback_t &reply_callback)
client & sdiffstore(const std::string &destination, const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
client & type(const std::string &key, const reply_callback_t &reply_callback)
client & client_pause(int timeout, const reply_callback_t &reply_callback)
void connection_disconnection_handler(network::redis_connection &connection)
client & strlen(const std::string &key, const reply_callback_t &reply_callback)
std::atomic_bool m_reconnecting
Definition: client.hpp:1094
client & script_load(const std::string &script, const reply_callback_t &reply_callback)
client & expire(const std::string &key, int seconds, const reply_callback_t &reply_callback)
std::future< reply > cluster_nodes()
std::future< reply > dbsize()
client & del(const std::vector< std::string > &key, const reply_callback_t &reply_callback)
client & pfcount(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
std::string m_redis_server
Definition: client.hpp:1046
client & lpop(const std::string &key, const reply_callback_t &reply_callback)
std::future< reply > role()
void client_kill_impl(std::vector< std::string > &redis_cmd, reply_callback_t &reply, const T &arg, const Ts &... args)
Definition: client.ipp:66
std::mutex m_callbacks_mutex
Definition: client.hpp:1113
std::future< reply > bgsave()
client & debug_object(const std::string &key, const reply_callback_t &reply_callback)
client & cluster_set_config_epoch(const std::string &epoch, const reply_callback_t &reply_callback)
client & wait(int numslaves, int timeout, const reply_callback_t &reply_callback)
client & zrank(const std::string &key, const std::string &member, const reply_callback_t &reply_callback)
client & srem(const std::string &key, const std::vector< std::string > &members, const reply_callback_t &reply_callback)
std::future< reply > flushdb()
client & rpop(const std::string &key, const reply_callback_t &reply_callback)
client & sdiff(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
client & sync_commit(const std::chrono::duration< Rep, Period > &timeout)
Definition: client.hpp:212
client & cluster_slaves(const std::string &node_id, const reply_callback_t &reply_callback)
client & getset(const std::string &key, const std::string &val, const reply_callback_t &reply_callback)
client & pfadd(const std::string &key, const std::vector< std::string > &elements, const reply_callback_t &reply_callback)
bool is_reconnecting(void) const
client & renamenx(const std::string &key, const std::string &newkey, const reply_callback_t &reply_callback)
connect_state
Definition: client.hpp:66
client & decr(const std::string &key, const reply_callback_t &reply_callback)
std::function< void(reply &)> reply_callback_t
Definition: client.hpp:164
std::future< reply > monitor()
std::size_t m_redis_port
Definition: client.hpp:1050
std::future< reply > lastsave()
void disconnect(bool wait_for_removal=false)
client & auth(const std::string &password, const reply_callback_t &reply_callback)
void resend_failed_commands(void)
client & sync_commit(void)
client & ltrim(const std::string &key, int start, int stop, const reply_callback_t &reply_callback)
std::future< reply > client_list()
client & hincrby(const std::string &key, const std::string &field, int incr, const reply_callback_t &reply_callback)
client & linsert(const std::string &key, const std::string &before_after, const std::string &pivot, const std::string &value, const reply_callback_t &reply_callback)
client & lrem(const std::string &key, int count, const std::string &value, const reply_callback_t &reply_callback)
std::future< reply > time()
client & zcount(const std::string &key, int min, int max, const reply_callback_t &reply_callback)
network::redis_connection m_client
Definition: client.hpp:1067
std::future< reply > discard()
client & smove(const std::string &source, const std::string &destination, const std::string &member, const reply_callback_t &reply_callback)
client & send(const std::vector< std::string > &redis_cmd, const reply_callback_t &callback)
client & pexpireat(const std::string &key, int milliseconds_timestamp, const reply_callback_t &reply_callback)
client & client_reply(const std::string &mode, const reply_callback_t &reply_callback)
client & cluster_replicate(const std::string &node_id, const reply_callback_t &reply_callback)
client & zadd(const std::string &key, const std::vector< std::string > &options, const std::map< std::string, std::string > &score_members, const reply_callback_t &reply_callback)
client & ttl(const std::string &key, const reply_callback_t &reply_callback)
Definition: sentinel.hpp:34
client & hkeys(const std::string &key, const reply_callback_t &reply_callback)
client & zrevrank(const std::string &key, const std::string &member, const reply_callback_t &reply_callback)
client & expireat(const std::string &key, int timestamp, const reply_callback_t &reply_callback)
client & incr(const std::string &key, const reply_callback_t &reply_callback)
client & setex(const std::string &key, int seconds, const std::string &value, const reply_callback_t &reply_callback)
client & hvals(const std::string &key, const reply_callback_t &reply_callback)
client & bitop(const std::string &operation, const std::string &destkey, const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
void unprotected_auth(const std::string &password, const reply_callback_t &reply_callback)
client & hsetnx(const std::string &key, const std::string &field, const std::string &value, const reply_callback_t &reply_callback)
client & bitpos(const std::string &key, int bit, const reply_callback_t &reply_callback)
client & cluster_count_failure_reports(const std::string &node_id, const reply_callback_t &reply_callback)
client & persist(const std::string &key, const reply_callback_t &reply_callback)
std::condition_variable m_sync_condvar
Definition: client.hpp:1118
client & hmset(const std::string &key, const std::vector< std::pair< std::string, std::string >> &field_val, const reply_callback_t &reply_callback)
std::string m_password
Definition: client.hpp:1058
client & mset(const std::vector< std::pair< std::string, std::string >> &key_vals, const reply_callback_t &reply_callback)
client & move(const std::string &key, const std::string &db, const reply_callback_t &reply_callback)
client & decrby(const std::string &key, int val, const reply_callback_t &reply_callback)
void try_commit(void)
#define __CPP_REDIS_LOG(level, msg)
Definition: logger.hpp:212
client & zrem(const std::string &key, const std::vector< std::string > &members, const reply_callback_t &reply_callback)
client & setrange(const std::string &key, int offset, const std::string &value, const reply_callback_t &reply_callback)
client & rename(const std::string &key, const std::string &newkey, const reply_callback_t &reply_callback)
void clear_sentinels(void)
client & migrate(const std::string &host, int port, const std::string &key, const std::string &dest_db, int timeout, const reply_callback_t &reply_callback)
client & info(const reply_callback_t &reply_callback)
std::enable_if< std::is_same< T, client_type >::value >::type client_kill_unpack_arg(std::vector< std::string > &redis_cmd, reply_callback_t &, client_type type)
client kill impl
Definition: client.ipp:30
client & mget(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
std::future< reply > quit()
client & echo(const std::string &msg, const reply_callback_t &reply_callback)
client & watch(const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
client & evalsha(const std::string &sha1, int numkeys, const std::vector< std::string > &keys, const std::vector< std::string > &args, const reply_callback_t &reply_callback)
client & incrbyfloat(const std::string &key, float incr, const reply_callback_t &reply_callback)
std::future< reply > multi()
client & geopos(const std::string &key, const std::vector< std::string > &members, const reply_callback_t &reply_callback)
void add_sentinel(const std::string &host, std::size_t port)
client & script_exists(const std::vector< std::string > &scripts, const reply_callback_t &reply_callback)
client & lrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback)
client & command_info(const std::vector< std::string > &command_name, const reply_callback_t &reply_callback)
std::queue< command_request > m_commands
Definition: client.hpp:1103
client & zcard(const std::string &key, const reply_callback_t &reply_callback)
void connect(const std::string &host="127.0.0.1", std::size_t port=6379, const connect_callback_t &connect_callback=nullptr, std::uint32_t timeout_msecs=0, std::int32_t max_reconnects=0, std::uint32_t reconnect_interval_msecs=0)
client & zrevrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback)
const sentinel & get_sentinel(void) const
std::int32_t m_max_reconnects
Definition: client.hpp:1081
std::future< reply > config_resetstat()
client_type
Definition: client.hpp:49
cpp_redis::sentinel m_sentinel
Definition: client.hpp:1072
client & slowlog(const std::string subcommand, const reply_callback_t &reply_callback)
client & zrange(const std::string &key, int start, int stop, const reply_callback_t &reply_callback)
std::future< reply > randomkey()
bool should_reconnect(void) const
client & pfmerge(const std::string &destkey, const std::vector< std::string > &sourcekeys, const reply_callback_t &reply_callback)
client & hincrbyfloat(const std::string &key, const std::string &field, float incr, const reply_callback_t &reply_callback)
void debug(const std::string &msg, const std::string &file, std::size_t line)
client & incrby(const std::string &key, int incr, const reply_callback_t &reply_callback)
client & append(const std::string &key, const std::string &value, const reply_callback_t &reply_callback)
std::future< reply > client_getname()
client & cluster_keyslot(const std::string &key, const reply_callback_t &reply_callback)
client & sinterstore(const std::string &destination, const std::vector< std::string > &keys, const reply_callback_t &reply_callback)
void clear_callbacks(void)
client & hgetall(const std::string &key, const reply_callback_t &reply_callback)
void re_auth(void)
client & config_set(const std::string &param, const std::string &val, const reply_callback_t &reply_callback)
client & cluster_addslots(const std::vector< std::string > &p_slots, const reply_callback_t &reply_callback)
client & slaveof(const std::string &host, int port, const reply_callback_t &reply_callback)
std::function< void(const std::string &host, std::size_t port, connect_state status)> connect_callback_t
Definition: client.hpp:101
std::future< reply > shutdown()
client & keys(const std::string &pattern, const reply_callback_t &reply_callback)
client & lpush(const std::string &key, const std::vector< std::string > &values, const reply_callback_t &reply_callback)
std::future< reply > script_flush()
std::atomic< unsigned int > m_callbacks_running
Definition: client.hpp:1123
client & cluster_reset(const reply_callback_t &reply_callback)
~client(void)
dtor
client & lpushx(const std::string &key, const std::string &value, const reply_callback_t &reply_callback)
bool is_connected(void) const
client & hlen(const std::string &key, const reply_callback_t &reply_callback)
client & eval(const std::string &script, int numkeys, const std::vector< std::string > &keys, const std::vector< std::string > &args, const reply_callback_t &reply_callback)
std::future< reply > cluster_slots()
client & geohash(const std::string &key, const std::vector< std::string > &members, const reply_callback_t &reply_callback)
void unprotected_select(int index, const reply_callback_t &reply_callback)
client & zscore(const std::string &key, const std::string &member, const reply_callback_t &reply_callback)
std::future< reply > readonly()
client & commit(void)
client & hmget(const std::string &key, const std::vector< std::string > &fields, const reply_callback_t &reply_callback)
Definition: array_builder.hpp:29
client & psetex(const std::string &key, int milliseconds, const std::string &val, const reply_callback_t &reply_callback)
client & dump(const std::string &key, const reply_callback_t &reply_callback)
std::vector< std::string > command
Definition: client.hpp:1038
client & script_debug(const std::string &mode, const reply_callback_t &reply_callback)
void reconnect(void)