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
aae0a1f9
Commit
aae0a1f9
authored
Jun 29, 2015
by
antirez
Browse files
Geo: GEOPOS command and tests.
parent
f6edd0cb
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/geo.c
View file @
aae0a1f9
...
@@ -709,3 +709,36 @@ void geoHashCommand(redisClient *c) {
...
@@ -709,3 +709,36 @@ void geoHashCommand(redisClient *c) {
}
}
}
}
}
}
/* GEOPOS key ele1 ele2 ... eleN
*
* Returns an array of two-items arrays representing the x,y position of each
* element specified in the arguments. For missing elements NULL is returned. */
void
geoposCommand
(
redisClient
*
c
)
{
int
j
;
/* Look up the requested zset */
robj
*
zobj
=
NULL
;
if
((
zobj
=
lookupKeyReadOrReply
(
c
,
c
->
argv
[
1
],
shared
.
emptymultibulk
))
==
NULL
||
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
/* Report elements one after the other, using a null bulk reply for
* missing elements. */
addReplyMultiBulkLen
(
c
,
c
->
argc
-
2
);
for
(
j
=
2
;
j
<
c
->
argc
;
j
++
)
{
double
score
;
if
(
zsetScore
(
zobj
,
c
->
argv
[
j
],
&
score
)
==
REDIS_ERR
)
{
addReply
(
c
,
shared
.
nullmultibulk
);
}
else
{
/* Decode... */
double
xy
[
2
];
if
(
!
decodeGeohash
(
score
,
xy
))
{
addReply
(
c
,
shared
.
nullmultibulk
);
continue
;
}
addReplyMultiBulkLen
(
c
,
2
);
addReplyDouble
(
c
,
xy
[
0
]);
addReplyDouble
(
c
,
xy
[
1
]);
}
}
}
src/redis.c
View file @
aae0a1f9
...
@@ -288,6 +288,7 @@ struct redisCommand redisCommandTable[] = {
...
@@ -288,6 +288,7 @@ struct redisCommand redisCommandTable[] = {
{
"geoencode"
,
geoEncodeCommand
,
-
3
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geoencode"
,
geoEncodeCommand
,
-
3
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geodecode"
,
geoDecodeCommand
,
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geodecode"
,
geoDecodeCommand
,
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geohash"
,
geoHashCommand
,
-
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geohash"
,
geoHashCommand
,
-
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"geopos"
,
geoposCommand
,
-
2
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"pfselftest"
,
pfselftestCommand
,
1
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"pfselftest"
,
pfselftestCommand
,
1
,
"r"
,
0
,
NULL
,
0
,
0
,
0
,
0
,
0
},
{
"pfadd"
,
pfaddCommand
,
-
2
,
"wmF"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"pfadd"
,
pfaddCommand
,
-
2
,
"wmF"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"pfcount"
,
pfcountCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
{
"pfcount"
,
pfcountCommand
,
-
2
,
"r"
,
0
,
NULL
,
1
,
1
,
1
,
0
,
0
},
...
...
src/redis.h
View file @
aae0a1f9
...
@@ -1564,6 +1564,7 @@ void geoRadiusByMemberCommand(redisClient *c);
...
@@ -1564,6 +1564,7 @@ void geoRadiusByMemberCommand(redisClient *c);
void
geoRadiusCommand
(
redisClient
*
c
);
void
geoRadiusCommand
(
redisClient
*
c
);
void
geoAddCommand
(
redisClient
*
c
);
void
geoAddCommand
(
redisClient
*
c
);
void
geoHashCommand
(
redisClient
*
c
);
void
geoHashCommand
(
redisClient
*
c
);
void
geoposCommand
(
redisClient
*
c
);
void
pfselftestCommand
(
redisClient
*
c
);
void
pfselftestCommand
(
redisClient
*
c
);
void
pfaddCommand
(
redisClient
*
c
);
void
pfaddCommand
(
redisClient
*
c
);
void
pfcountCommand
(
redisClient
*
c
);
void
pfcountCommand
(
redisClient
*
c
);
...
...
tests/unit/geo.tcl
View file @
aae0a1f9
...
@@ -92,6 +92,23 @@ start_server {tags {"geo"}} {
...
@@ -92,6 +92,23 @@ start_server {tags {"geo"}} {
lindex
[
r geohash points test
]
0
lindex
[
r geohash points test
]
0
}
{
ezs42e44yx0
}
}
{
ezs42e44yx0
}
test
{
GEOPOS simple
}
{
r del points
r geoadd points 10 20 a 30 40 b
lassign
[
lindex
[
r geopos points a b
]
0
]
x1 y1
lassign
[
lindex
[
r geopos points a b
]
1
]
x2 y2
assert
{
abs
(
$x1
- 10
)
< 0.001
}
assert
{
abs
(
$y1
- 20
)
< 0.001
}
assert
{
abs
(
$x2
- 30
)
< 0.001
}
assert
{
abs
(
$y2
- 40
)
< 0.001
}
}
test
{
GEOPOS missing element
}
{
r del points
r geoadd points 10 20 a 30 40 b
lindex
[
r geopos points a x b
]
1
}
{}
test
{
GEOADD + GEORANGE randomized test
}
{
test
{
GEOADD + GEORANGE randomized test
}
{
set attempt 10
set attempt 10
while
{[
incr attempt -1
]}
{
while
{[
incr attempt -1
]}
{
...
...
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