Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. // initialize redis
  2. bool redis_init(redisContext* c) {
  3.     c = redisConnect(REDIS_HOST, REDIS_PORT);
  4.  
  5.     if (c == NULL || c->err) {
  6.         if (c) {
  7.             printf("Redis connection error: %s\n", c->errstr);
  8.             redisFree(c);
  9.         } else
  10.             printf("Redis connection error: can't allocate redis context\n");
  11.  
  12.         return false;
  13.     }
  14.  
  15.     redisReply* redReply = reinterpret_cast<redisReply*>(redisCommand(c, "PING"));
  16.     printf("PING: %s\n", redReply->str);
  17.     freeReplyObject(redReply);
  18.  
  19.     printf("Redis started successfully\n");
  20.  
  21.     return true;
  22. }
  23.  
  24. my_function(redisContext* c) {
  25.     redisReply* redReply = reinterpret_cast<redisReply*>(redisCommand(c, "PING2"));
  26.     printf("PING2: %s\n", redReply->str);
  27.     freeReplyObject(redReply);
  28. }
  29.  
  30. int main(int argc, char* argv[]) {
  31.     redisContext* c;
  32.  
  33.     if (redis_init(c))
  34.         my_function(c);
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement