Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for Cygwin 2.x #97

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
/*.dylib
/*.a
/*.pc
/hiredis-test.exe
/.project
/.cproject
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file is released under the BSD license, see the COPYING file

OBJ=net.o hiredis.o sds.o async.o read.o hiarray.o hiutil.o command.o crc16.o adlist.o hircluster.o
EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib
EXAMPLES=hiredis-example hiredis-example-libevent hiredis-example-libev hiredis-example-glib hiredis-example-sync
TESTS=hiredis-test
LIBNAME=libhiredis_vip
PKGCONFNAME=hiredis_vip.pc
Expand Down Expand Up @@ -102,6 +102,9 @@ hiredis-example-libev: examples/example-libev.c adapters/libev.h $(STLIBNAME)
hiredis-example-glib: examples/example-glib.c adapters/glib.h $(STLIBNAME)
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) $(shell pkg-config --cflags --libs glib-2.0) -I. $< $(STLIBNAME)

hiredis-example-sync: examples/example-sync.c
$(CC) -o examples/$@ $(REAL_CFLAGS) $(REAL_LDFLAGS) -I. $< $(STLIBNAME)

ifndef AE_DIR
hiredis-example-ae:
@echo "Please specify AE_DIR (e.g. <redis repository>/src)"
Expand Down
17 changes: 17 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>

#include "command.h"
#include "hiutil.h"
Expand All @@ -19,6 +20,8 @@ redis_argz(struct cmd *r)
switch (r->type) {
case CMD_REQ_REDIS_PING:
case CMD_REQ_REDIS_QUIT:
case CMD_REQ_REDIS_INFO:
case CMD_REQ_REDIS_DBSIZE:
return 1;

default:
Expand Down Expand Up @@ -611,6 +614,12 @@ redis_parse_cmd(struct cmd *r)
break;
}

if (str4icmp(m, 'i', 'n', 'f', 'o')) {
r->type = CMD_REQ_REDIS_INFO;
r->noforward = 1;
break;
}

if (str4icmp(m, 'a', 'u', 't', 'h')) {
r->type = CMD_REQ_REDIS_AUTH;
r->noforward = 1;
Expand Down Expand Up @@ -813,6 +822,12 @@ redis_parse_cmd(struct cmd *r)
break;
}

if (str6icmp(m, 'd', 'b', 's', 'i', 'z', 'e')) {
r->type = CMD_REQ_REDIS_DBSIZE;
r->noforward = 1;
break;
}

break;

case 7:
Expand Down Expand Up @@ -940,6 +955,8 @@ redis_parse_cmd(struct cmd *r)
break;
}

break;

case 11:
if (str11icmp(m, 'i', 'n', 'c', 'r', 'b', 'y', 'f', 'l', 'o', 'a', 't')) {
r->type = CMD_REQ_REDIS_INCRBYFLOAT;
Expand Down
2 changes: 2 additions & 0 deletions command.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ typedef enum cmd_parse_result {
ACTION( REQ_REDIS_EVALSHA ) \
ACTION( REQ_REDIS_PING ) /* redis requests - ping/quit */ \
ACTION( REQ_REDIS_QUIT) \
ACTION( REQ_REDIS_INFO ) \
ACTION( REQ_REDIS_DBSIZE ) \
ACTION( REQ_REDIS_AUTH) \
ACTION( RSP_REDIS_STATUS ) /* redis response */ \
ACTION( RSP_REDIS_ERROR ) \
Expand Down
61 changes: 61 additions & 0 deletions examples/example-sync.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* example-sync.c
*
* Created on: 12.10.2018
* Author: tolj
*/

#include<stdio.h>
#include<hircluster.h>
int main()
{
char *key="key-a";
char *field="field-1";
char *key1="key1";
char *value1="value-1";
char *key2="key1";
char *value2="value-1";
redisClusterContext *cc;
redisReply *reply;

cc = redisClusterContextInit();
redisClusterSetOptionAddNodes(cc, "127.0.0.1:7000,127.0.0.1:7001,127.0.0.1:7002");
redisClusterSetOptionParseSlaves(cc);
redisClusterConnect2(cc);
if(cc == NULL || cc->err)
{
printf("connect error : %s\n", cc == NULL ? "NULL" : cc->errstr);
return -1;
}

test_cluster_update_route(cc);

printf("redisClusterDbSize %ld\n", (long)redisClusterDbSize(cc));

reply = redisClusterCommand(cc, "hmget %s %s", key, field);
if(reply == NULL)
{
printf("reply is null[%s]\n", cc->errstr);
redisClusterFree(cc);
return -1;
}

printf("reply->type:%d\n", reply->type);

freeReplyObject(reply);

reply = redisClusterCommand(cc, "mset %s %s %s %s", key1, value1, key2, value2);
if(reply == NULL)
{
printf("reply is null[%s]\n", cc->errstr);
redisClusterFree(cc);
return -1;
}

printf("reply->str:%s\n", reply->str);

freeReplyObject(reply);
redisClusterFree(cc);
return 0;
}

3 changes: 3 additions & 0 deletions fmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#define _POSIX_C_SOURCE 200112L
#elif defined(__linux__) || defined(__OpenBSD__) || defined(__NetBSD__)
#define _XOPEN_SOURCE 600
#elif defined(__CYGWIN__)
#define _XOPEN_SOURCE 600
#define _POSIX_C_SOURCE 200112L
#else
#define _XOPEN_SOURCE
#endif
Expand Down
Loading