| 89 | } |
| 90 | |
| 91 | Cache::Cache(unsigned port, bool allow_version_mismatch) { |
| 92 | const char *hostname = "127.0.0.1"; |
| 93 | struct timeval timeout = {1, 500000}; // 1.5 seconds |
| 94 | ctx = redisConnectWithTimeout(hostname, port, timeout); |
| 95 | if (!ctx) { |
| 96 | cerr << "Can't allocate redis context\n"; |
| 97 | exit(-1); |
| 98 | } |
| 99 | if (ctx->err) { |
| 100 | cerr << "Redis connection error: " << ctx->errstr << '\n'; |
| 101 | exit(-1); |
| 102 | } |
| 103 | string version; |
| 104 | if (remote_get("Alive2_version", version, ctx)) { |
| 105 | if (version != util::alive_version) { |
| 106 | cerr << "Cache version mismatch!\n" |
| 107 | "This version of Alive2 is " << util::alive_version << "\n" |
| 108 | "But the cache was created by version " << version << '\n'; |
| 109 | if (!allow_version_mismatch) |
| 110 | exit(-1); |
| 111 | } |
| 112 | } else { |
| 113 | remote_set("Alive2_version", util::alive_version, ctx); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | Cache::~Cache() { |
| 118 | redisFree(ctx); |
nothing calls this directly
no test coverage detected