summaryrefslogtreecommitdiff
path: root/examples/example.c
diff options
context:
space:
mode:
authorMark Nunberg <mnunberg@users.noreply.github.com>2019-08-09 04:02:53 -0400
committerGitHub <noreply@github.com>2019-08-09 04:02:53 -0400
commitf9bccfb7baa0bd0c9fdbaee602398590ea364f67 (patch)
treee94e828e31b9f71166436c2a560f33f650ffb13e /examples/example.c
parent300fc013c1559ece991abcbf886c86e807c36ba4 (diff)
parent5d013039a95402ff555ab51a7340d4af91b6f72b (diff)
Merge branch 'master' into createArray-size_t
Diffstat (limited to 'examples/example.c')
-rw-r--r--examples/example.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/examples/example.c b/examples/example.c
index 4d494c5..0e93fc8 100644
--- a/examples/example.c
+++ b/examples/example.c
@@ -5,14 +5,27 @@
#include <hiredis.h>
int main(int argc, char **argv) {
- unsigned int j;
+ unsigned int j, isunix = 0;
redisContext *c;
redisReply *reply;
const char *hostname = (argc > 1) ? argv[1] : "127.0.0.1";
+
+ if (argc > 2) {
+ if (*argv[2] == 'u' || *argv[2] == 'U') {
+ isunix = 1;
+ /* in this case, host is the path to the unix socket */
+ printf("Will connect to unix socket @%s\n", hostname);
+ }
+ }
+
int port = (argc > 2) ? atoi(argv[2]) : 6379;
struct timeval timeout = { 1, 500000 }; // 1.5 seconds
- c = redisConnectWithTimeout(hostname, port, timeout);
+ if (isunix) {
+ c = redisConnectUnixWithTimeout(hostname, timeout);
+ } else {
+ c = redisConnectWithTimeout(hostname, port, timeout);
+ }
if (c == NULL || c->err) {
if (c) {
printf("Connection error: %s\n", c->errstr);