MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / getRedisContext

Function getRedisContext

src/keydb-diagnostic-tool.cpp:219–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219static redisContext *getRedisContext(const char *ip, int port,
220 const char *hostsocket)
221{
222 redisContext *ctx = NULL;
223 redisReply *reply = NULL;
224 if (hostsocket == NULL)
225 ctx = redisConnect(ip, port);
226 else
227 ctx = redisConnectUnix(hostsocket);
228 if (ctx == NULL || ctx->err) {
229 fprintf(stderr,"Could not connect to Redis at ");
230 const char *err = (ctx != NULL ? ctx->errstr : "");
231 if (hostsocket == NULL)
232 fprintf(stderr,"%s:%d: %s\n",ip,port,err);
233 else
234 fprintf(stderr,"%s: %s\n",hostsocket,err);
235 goto cleanup;
236 }
237 if (config.auth == NULL)
238 return ctx;
239 if (config.user == NULL)
240 reply = (redisReply*)redisCommand(ctx,"AUTH %s", config.auth);
241 else
242 reply = (redisReply*)redisCommand(ctx,"AUTH %s %s", config.user, config.auth);
243 if (reply != NULL) {
244 if (reply->type == REDIS_REPLY_ERROR) {
245 if (hostsocket == NULL)
246 fprintf(stderr, "Node %s:%d replied with error:\n%s\n", ip, port, reply->str);
247 else
248 fprintf(stderr, "Node %s replied with error:\n%s\n", hostsocket, reply->str);
249 goto cleanup;
250 }
251 freeReplyObject(reply);
252 return ctx;
253 }
254 fprintf(stderr, "ERROR: failed to fetch reply from ");
255 if (hostsocket == NULL)
256 fprintf(stderr, "%s:%d\n", ip, port);
257 else
258 fprintf(stderr, "%s\n", hostsocket);
259cleanup:
260 freeReplyObject(reply);
261 redisFree(ctx);
262 return NULL;
263}
264
265static void freeClient(client c) {
266 aeEventLoop *el = CLIENT_GET_EVENTLOOP(c);

Callers 1

mainFunction · 0.70

Calls 5

redisConnectFunction · 0.85
redisConnectUnixFunction · 0.85
freeReplyObjectFunction · 0.85
redisFreeFunction · 0.85
redisCommandClass · 0.70

Tested by

no test coverage detected