Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
29e3ff9b
Commit
29e3ff9b
authored
Jun 14, 2017
by
Salvatore Sanfilippo
Committed by
GitHub
Jun 14, 2017
Browse files
Merge pull request #3926 from QuChen88/3.2
Implement getKeys procedure for georadius and georadiusbymember commands
parents
5116130d
bacb04f8
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/db.c
View file @
29e3ff9b
...
@@ -1234,6 +1234,44 @@ int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkey
...
@@ -1234,6 +1234,44 @@ int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkey
return
keys
;
return
keys
;
}
}
/* Helper function to extract keys from following commands:
* GEORADIUS key x y radius unit [WITHDIST] [WITHHASH] [WITHCOORD] [ASC|DESC]
* [COUNT count] [STORE key] [STOREDIST key]
* GEORADIUSBYMEMBER key member radius unit ... options ... */
int
*
georadiusGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
)
{
int
i
,
num
,
*
keys
;
UNUSED
(
cmd
);
/* Check for the presence of the stored key in the command */
int
stored_key
=
-
1
;
for
(
i
=
5
;
i
<
argc
;
i
++
)
{
char
*
arg
=
argv
[
i
]
->
ptr
;
/* For the case when user specifies both "store" and "storedist" options, the
* second key specified would override the first key. This behavior is kept
* the same as in georadiusCommand method.
*/
if
((
!
strcasecmp
(
arg
,
"store"
)
||
!
strcasecmp
(
arg
,
"storedist"
))
&&
((
i
+
1
)
<
argc
))
{
stored_key
=
i
+
1
;
i
++
;
}
}
num
=
1
+
(
stored_key
==
-
1
?
0
:
1
);
/* Keys in the command come from two places:
* argv[1] = key,
* argv[5...n] = stored key if present
*/
keys
=
zmalloc
(
sizeof
(
int
)
*
num
);
/* Add all key positions to keys[] */
keys
[
0
]
=
1
;
if
(
num
>
1
)
{
keys
[
1
]
=
stored_key
;
}
*
numkeys
=
num
;
return
keys
;
}
/* Slot to Key API. This is used by Redis Cluster in order to obtain in
/* Slot to Key API. This is used by Redis Cluster in order to obtain in
* a fast way a key that belongs to a specified hash slot. This is useful
* a fast way a key that belongs to a specified hash slot. This is useful
* while rehashing the cluster. */
* while rehashing the cluster. */
...
...
src/server.c
View file @
29e3ff9b
...
@@ -284,8 +284,8 @@ struct redisCommand redisCommandTable[] = {
...
@@ -284,8 +284,8 @@ struct redisCommand redisCommandTable[] = {
{
"wait"
,
waitCommand
,
3
,
"s"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"wait"
,
waitCommand
,
3
,
"s"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"command"
,
commandCommand
,
0
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"command"
,
commandCommand
,
0
,
"lt"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geoadd"
,
geoaddCommand
,
-
5
,
"wm"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geoadd"
,
geoaddCommand
,
-
5
,
"wm"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"georadius"
,
georadiusCommand
,
-
6
,
"w"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"georadius"
,
georadiusCommand
,
-
6
,
"w"
,
0
,
georadiusGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"georadiusbymember"
,
georadiusByMemberCommand
,
-
5
,
"w"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"georadiusbymember"
,
georadiusByMemberCommand
,
-
5
,
"w"
,
0
,
georadiusGetKeys
,
1
,
1
,
1
,
0
,
0
},
{
"geohash"
,
geohashCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geohash"
,
geohashCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geopos"
,
geoposCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geopos"
,
geoposCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geodist"
,
geodistCommand
,
-
4
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"geodist"
,
geodistCommand
,
-
4
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
...
...
src/server.h
View file @
29e3ff9b
...
@@ -1435,6 +1435,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *num
...
@@ -1435,6 +1435,7 @@ int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *num
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
evalGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
sortGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
sortGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
migrateGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
migrateGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
int
*
georadiusGetKeys
(
struct
redisCommand
*
cmd
,
robj
**
argv
,
int
argc
,
int
*
numkeys
);
/* Cluster */
/* Cluster */
void
clusterInit
(
void
);
void
clusterInit
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment