build ssl example if ssl is enabled

This commit is contained in:
Mark Nunberg 2019-04-10 08:36:34 -04:00
parent 4830786c84
commit dc3c6ce85c
2 changed files with 11 additions and 2 deletions

View File

@ -37,5 +37,10 @@ IF (APPLE)
TARGET_LINK_LIBRARIES(example-macosx hiredis ${CF})
ENDIF()
IF (HIREDIS_SSL)
ADD_EXECUTABLE(example-ssl example-ssl.c)
TARGET_LINK_LIBRARIES(example-ssl hiredis)
ENDIF()
ADD_EXECUTABLE(example example.c)
TARGET_LINK_LIBRARIES(example hiredis)

View File

@ -18,8 +18,12 @@ int main(int argc, char **argv) {
const char *key = argv[4];
const char *ca = argc > 4 ? argv[5] : NULL;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
c = redisConnectWithTimeout(hostname, port, timeout);
struct timeval tv = { 1, 500000 }; // 1.5 seconds
redisOptions options = {0};
REDIS_OPTIONS_SET_TCP(&options, hostname, port);
options.timeout = &tv;
c = redisConnectWithOptions(&options);
if (c == NULL || c->err) {
if (c) {
printf("Connection error: %s\n", c->errstr);