1
0
mirror of https://github.com/fluencelabs/redis synced 2025-06-28 08:21:32 +00:00
Files
.github
deps
hiredis
adapters
examples
CMakeLists.txt
example-ae.c
example-glib.c
example-ivykis.c
example-libev.c
example-libevent-ssl.c
example-libevent.c
example-libuv.c
example-macosx.c
example-qt.cpp
example-qt.h
example-ssl.c
example.c
.gitignore
.travis.yml
CHANGELOG.md
CMakeLists.txt
COPYING
Makefile
README.md
appveyor.yml
async.c
async.h
async_private.h
dict.c
dict.h
fmacros.h
hiredis.c
hiredis.h
hiredis.pc.in
hiredis_ssl.h
hiredis_ssl.pc.in
net.c
net.h
read.c
read.h
sds.c
sds.h
sdsalloc.h
sockcompat.c
sockcompat.h
ssl.c
test.c
test.sh
win32.h
jemalloc
linenoise
lua
Makefile
README.md
update-jemalloc.sh
src
tests
utils
.gitignore
00-RELEASENOTES
BUGS
CONTRIBUTING
COPYING
INSTALL
MANIFESTO
Makefile
README.md
TLS.md
redis.conf
runtest
runtest-cluster
runtest-moduleapi
runtest-sentinel
sentinel.conf
redis/deps/hiredis/examples/example-libevent-ssl.c

74 lines
2.0 KiB
C
Raw Normal View History

2019-09-20 20:06:47 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <hiredis.h>
#include <hiredis_ssl.h>
#include <async.h>
#include <adapters/libevent.h>
void getCallback(redisAsyncContext *c, void *r, void *privdata) {
redisReply *reply = r;
if (reply == NULL) return;
printf("argv[%s]: %s\n", (char*)privdata, reply->str);
/* Disconnect after receiving the reply to GET */
redisAsyncDisconnect(c);
}
void connectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Connected...\n");
}
void disconnectCallback(const redisAsyncContext *c, int status) {
if (status != REDIS_OK) {
printf("Error: %s\n", c->errstr);
return;
}
printf("Disconnected...\n");
}
int main (int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
struct event_base *base = event_base_new();
if (argc < 5) {
fprintf(stderr,
"Usage: %s <key> <host> <port> <cert> <certKey> [ca]\n", argv[0]);
exit(1);
}
const char *value = argv[1];
size_t nvalue = strlen(value);
const char *hostname = argv[2];
int port = atoi(argv[3]);
const char *cert = argv[4];
const char *certKey = argv[5];
const char *caCert = argc > 5 ? argv[6] : NULL;
redisAsyncContext *c = redisAsyncConnect(hostname, port);
if (c->err) {
/* Let *c leak for now... */
printf("Error: %s\n", c->errstr);
return 1;
}
if (redisSecureConnection(&c->c, caCert, cert, certKey, "sni") != REDIS_OK) {
printf("SSL Error!\n");
exit(1);
}
redisLibeventAttach(c,base);
redisAsyncSetConnectCallback(c,connectCallback);
redisAsyncSetDisconnectCallback(c,disconnectCallback);
redisAsyncCommand(c, NULL, NULL, "SET key %b", value, nvalue);
redisAsyncCommand(c, getCallback, (char*)"end-1", "GET key");
event_base_dispatch(base);
return 0;
}