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

Function main

deps/hiredis/examples/example-libevent-ssl.c:36–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36int main (int argc, char **argv) {
37#ifndef _WIN32
38 signal(SIGPIPE, SIG_IGN);
39#endif
40
41 struct event_base *base = event_base_new();
42 if (argc < 5) {
43 fprintf(stderr,
44 "Usage: %s <key> <host> <port> <cert> <certKey> [ca]\n", argv[0]);
45 exit(1);
46 }
47
48 const char *value = argv[1];
49 size_t nvalue = strlen(value);
50
51 const char *hostname = argv[2];
52 int port = atoi(argv[3]);
53
54 const char *cert = argv[4];
55 const char *certKey = argv[5];
56 const char *caCert = argc > 5 ? argv[6] : NULL;
57
58 redisSSLContext *ssl;
59 redisSSLContextError ssl_error;
60
61 redisInitOpenSSL();
62
63 ssl = redisCreateSSLContext(caCert, NULL,
64 cert, certKey, NULL, &ssl_error);
65 if (!ssl) {
66 printf("Error: %s\n", redisSSLContextGetError(ssl_error));
67 return 1;
68 }
69
70 redisAsyncContext *c = redisAsyncConnect(hostname, port);
71 if (c->err) {
72 /* Let *c leak for now... */
73 printf("Error: %s\n", c->errstr);
74 return 1;
75 }
76 if (redisInitiateSSLWithContext(&c->c, ssl) != REDIS_OK) {
77 printf("SSL Error!\n");
78 exit(1);
79 }
80
81 redisLibeventAttach(c,base);
82 redisAsyncSetConnectCallback(c,connectCallback);
83 redisAsyncSetDisconnectCallback(c,disconnectCallback);
84 redisAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue);
85 redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
86 event_base_dispatch(base);
87
88 redisFreeSSLContext(ssl);
89 return 0;
90}

Callers

nothing calls this directly

Calls 10

redisInitOpenSSLFunction · 0.85
redisCreateSSLContextFunction · 0.85
redisSSLContextGetErrorFunction · 0.85
redisAsyncConnectFunction · 0.85
redisLibeventAttachFunction · 0.85
redisAsyncCommandFunction · 0.85
redisFreeSSLContextFunction · 0.85

Tested by

no test coverage detected