Permalink
Browse files

Add the PING command.

  • Loading branch information...
1 parent 9a60fdb commit 1dac3327b8991aa4dd48c964fbcf99894810f39e @avm committed Jul 16, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 redisclient.h
View
@@ -59,6 +59,7 @@
#define REDIS_LBR "\r\n"
#define REDIS_STATUS_REPLY_OK "OK"
+#define REDIS_STATUS_REPLY_PONG "PONG"
#define REDIS_PREFIX_STATUS_REPLY_ERROR "-ERR "
#define REDIS_PREFIX_STATUS_REPLY_ERR_C '-'
#define REDIS_PREFIX_STATUS_REPLY_VALUE '+'
@@ -509,6 +510,17 @@ namespace redis
{
return connections_;
}
+
+ void ping()
+ {
+ if( connections_.size() > 1 )
+ throw std::runtime_error("feature is not available in cluster mode");
+
+ int socket = connections_[0].socket;
+ send_(socket, makecmd("PING"));
+ if (recv_single_line_reply_(socket) != REDIS_STATUS_REPLY_PONG)
+ throw protocol_error("expected a PONG response");
+ }
void auth(const string_type & pass)
{

0 comments on commit 1dac332

Please sign in to comment.