| 31 | } |
| 32 | |
| 33 | static bool remote_get(const string &key, string &value, redisContext *ctx) { |
| 34 | assert(ctx); |
| 35 | redisReply *reply = (redisReply *)redisCommand(ctx, "GET %s", key.data()); |
| 36 | if (!reply || ctx->err) { |
| 37 | cerr << "Redis error in remote_get: " << ctx->errstr << "\n"; |
| 38 | exit(-1); |
| 39 | } |
| 40 | if (reply->type == REDIS_REPLY_NIL) { |
| 41 | // not found |
| 42 | freeReplyObject(reply); |
| 43 | return false; |
| 44 | } else if (reply->type == REDIS_REPLY_STRING) { |
| 45 | // found |
| 46 | value = reply->str; |
| 47 | freeReplyObject(reply); |
| 48 | return true; |
| 49 | } else { |
| 50 | cerr << "Redis protocol error in remote_get, didn't expect reply type " |
| 51 | << redis_reply_string(reply->type) << "\n"; |
| 52 | exit(-1); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | static void remote_set(const string &key, const string &value, redisContext *ctx) { |
| 57 | assert(ctx); |
no test coverage detected