Skip to content

Commit

Permalink
added support for redis geo GEOADD, GEOHASH, GEOPOS, GEORADIUS, GEODI…
Browse files Browse the repository at this point in the history
…ST, GEORADIUSBYMEMBER commands
  • Loading branch information
sheldon-sminq committed Aug 14, 2018
1 parent 6211bc6 commit 861d5da
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/dyn_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ typedef enum msg_parse_result {
ACTION( REQ_REDIS_ZSCAN) \
ACTION( REQ_REDIS_EVAL ) /* redis requests - eval */ \
ACTION( REQ_REDIS_EVALSHA ) \
ACTION( REQ_REDIS_GEOADD ) /* redis geo requests */ \
ACTION( REQ_REDIS_GEORADIUS ) \
ACTION( REQ_REDIS_GEODIST ) \
ACTION( REQ_REDIS_GEOHASH ) \
ACTION( REQ_REDIS_GEOPOS ) \
ACTION( REQ_REDIS_GEORADIUSBYMEMBER ) \
/* ACTION( REQ_REDIS_AUTH) */ \
/* ACTION( REQ_REDIS_SELECT)*/ /* only during init */ \
ACTION( REQ_REDIS_PFADD ) /* redis requests - hyperloglog */ \
Expand Down
4 changes: 4 additions & 0 deletions src/dyn_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ ssize_t _dn_recvn(int sd, void *vptr, size_t n);
(str15icmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14) && \
(m[15] == c15 || m[15] == (c15 ^ 0x20)))

#define str17icmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16) \
(str16icmp(m, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15) && \
(m[16] == c16 || m[16] == (c16 ^ 0x20)))




Expand Down
42 changes: 41 additions & 1 deletion src/proto/dyn_redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ redis_argn(struct msg *r)
case MSG_REQ_REDIS_ZUNIONSTORE:
case MSG_REQ_REDIS_ZSCAN:
case MSG_REQ_REDIS_PFADD:
case MSG_REQ_REDIS_GEOADD:
case MSG_REQ_REDIS_GEORADIUS:
case MSG_REQ_REDIS_GEODIST:
case MSG_REQ_REDIS_GEOHASH:
case MSG_REQ_REDIS_GEOPOS:
case MSG_REQ_REDIS_GEORADIUSBYMEMBER:
return true;

default:
Expand Down Expand Up @@ -1008,6 +1014,16 @@ redis_parse_req(struct msg *r, const struct string *hash_tag)
r->is_read = 1;
break;
}
if (str6icmp(m, 'g', 'e', 'o', 'a', 'd', 'd')) {
r->type = MSG_REQ_REDIS_GEOADD;
r->is_read = 0;
break;
}
if (str6icmp(m, 'g', 'e', 'o', 'p', 'o', 's')) {
r->type = MSG_REQ_REDIS_GEOPOS;
r->is_read = 1;
break;
}

break;

Expand Down Expand Up @@ -1078,7 +1094,17 @@ redis_parse_req(struct msg *r, const struct string *hash_tag)
r->is_read = 0;
break;
}

if (str7icmp(m, 'g', 'e', 'o', 'h', 'a', 's', 'h')) {
r->type = MSG_REQ_REDIS_GEOHASH;
r->is_read = 1;
break;
}
if (str7icmp(m, 'g', 'e', 'o', 'd', 'i', 's', 't')) {
r->type = MSG_REQ_REDIS_GEODIST;
r->is_read = 1;
break;
}

break;

case 8:
Expand Down Expand Up @@ -1151,6 +1177,12 @@ redis_parse_req(struct msg *r, const struct string *hash_tag)
break;
}

if (str9icmp(m, 'g', 'e', 'o', 'r', 'a', 'd', 'i', 'u', 's')) {
r->type = MSG_REQ_REDIS_GEORADIUS;
r->is_read = 1;
break;
}

break;

case 10:
Expand Down Expand Up @@ -1264,6 +1296,14 @@ redis_parse_req(struct msg *r, const struct string *hash_tag)

break;

case 17:
if (str17icmp(m, 'g', 'e', 'o', 'r', 'a', 'd', 'i', 'u', 's', 'b', 'y', 'm', 'e', 'm', 'b','e','r')) {
r->type = MSG_REQ_REDIS_GEORADIUSBYMEMBER;
r->is_read = 1;
break;
}

break;
default:
r->is_read = 1;
break;
Expand Down

0 comments on commit 861d5da

Please sign in to comment.