Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
f193b3ca
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f193b3ca
编写于
6月 22, 2015
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Geo: removed bool usage from Geo code inside Redis
上级
73134f6a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
34 addition
and
34 deletion
+34
-34
src/geo.c
src/geo.c
+27
-26
src/zset.c
src/zset.c
+6
-6
src/zset.h
src/zset.h
+1
-2
未找到文件。
src/geo.c
浏览文件 @
f193b3ca
...
...
@@ -47,36 +47,36 @@
/* ====================================================================
* Helpers
* ==================================================================== */
static
inline
bool
decodeGeohash
(
double
bits
,
double
*
latlong
)
{
static
inline
int
decodeGeohash
(
double
bits
,
double
*
latlong
)
{
GeoHashBits
hash
=
{
.
bits
=
(
uint64_t
)
bits
,
.
step
=
GEO_STEP_MAX
};
return
geohashDecodeToLatLongWGS84
(
hash
,
latlong
);
}
/* Input Argument Helper */
/* Take a pointer to the latitude arg then use the next arg for longitude */
static
inline
bool
extractLatLongOrReply
(
redisClient
*
c
,
robj
**
argv
,
static
inline
int
extractLatLongOrReply
(
redisClient
*
c
,
robj
**
argv
,
double
*
latlong
)
{
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
if
(
getDoubleFromObjectOrReply
(
c
,
argv
[
i
],
latlong
+
i
,
NULL
)
!=
REDIS_OK
)
{
return
false
;
return
0
;
}
}
return
true
;
return
1
;
}
/* Input Argument Helper */
/* Decode lat/long from a zset member's score */
static
bool
latLongFromMember
(
robj
*
zobj
,
robj
*
member
,
double
*
latlong
)
{
static
int
latLongFromMember
(
robj
*
zobj
,
robj
*
member
,
double
*
latlong
)
{
double
score
=
0
;
if
(
!
zsetScore
(
zobj
,
member
,
&
score
))
return
false
;
return
0
;
if
(
!
decodeGeohash
(
score
,
latlong
))
return
false
;
return
0
;
return
true
;
return
1
;
}
/* Input Argument Helper */
...
...
@@ -124,7 +124,7 @@ static void latLongToGeojsonAndReply(redisClient *c, struct geojsonPoint *gp,
static
void
decodeGeohashToGeojsonBoundsAndReply
(
redisClient
*
c
,
uint64_t
hashbits
,
struct
geojsonPoint
*
gp
)
{
GeoHashArea
area
=
{
{
0
}
};
GeoHashArea
area
=
{
{
0
,
0
},{
0
,
0
},{
0
,
0
}
};
GeoHashBits
hash
=
{
.
bits
=
hashbits
,
.
step
=
GEO_STEP_MAX
};
geohashDecodeWGS84
(
hash
,
&
area
);
...
...
@@ -171,6 +171,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
double
y
,
double
radius
)
{
list
*
l
=
NULL
;
GeoHashBits
neighbors
[
9
];
unsigned
int
i
;
neighbors
[
0
]
=
n
.
hash
;
neighbors
[
1
]
=
n
.
neighbors
.
north
;
...
...
@@ -184,7 +185,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
/* For each neighbor (*and* our own hashbox), get all the matching
* members and add them to the potential result list. */
for
(
i
nt
i
=
0
;
i
<
sizeof
(
neighbors
)
/
sizeof
(
*
neighbors
);
i
++
)
{
for
(
i
=
0
;
i
<
sizeof
(
neighbors
)
/
sizeof
(
*
neighbors
);
i
++
)
{
list
*
r
;
if
(
HASHISZERO
(
neighbors
[
i
]))
...
...
@@ -213,7 +214,7 @@ static list *membersOfAllNeighbors(robj *zobj, GeoHashRadius n, double x,
listRewind
(
l
,
&
li
);
while
((
ln
=
listNext
(
&
li
)))
{
struct
zipresult
*
zr
=
listNodeValue
(
ln
);
GeoHashArea
area
=
{
{
0
}
};
GeoHashArea
area
=
{
{
0
,
0
},{
0
,
0
},{
0
,
0
}
};
GeoHashBits
hash
=
{
.
bits
=
(
uint64_t
)
zr
->
score
,
.
step
=
GEO_STEP_MAX
};
...
...
@@ -433,31 +434,31 @@ static void geoRadiusGeneric(redisClient *c, int type) {
sds
units
=
c
->
argv
[
base_args
-
2
+
1
]
->
ptr
;
/* Discover and populate all optional parameters. */
bool
withdist
=
false
,
withhash
=
false
,
withcoords
=
false
,
withgeojson
=
false
,
withgeojsonbounds
=
false
,
withgeojsoncollection
=
false
,
noproperties
=
false
;
int
withdist
=
0
,
withhash
=
0
,
withcoords
=
0
,
withgeojson
=
0
,
withgeojsonbounds
=
0
,
withgeojsoncollection
=
0
,
noproperties
=
0
;
int
sort
=
SORT_NONE
;
if
(
c
->
argc
>
base_args
)
{
int
remaining
=
c
->
argc
-
base_args
;
for
(
int
i
=
0
;
i
<
remaining
;
i
++
)
{
char
*
arg
=
c
->
argv
[
base_args
+
i
]
->
ptr
;
if
(
!
strncasecmp
(
arg
,
"withdist"
,
8
))
withdist
=
true
;
withdist
=
1
;
else
if
(
!
strcasecmp
(
arg
,
"withhash"
))
withhash
=
true
;
withhash
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withcoord"
,
9
))
withcoords
=
true
;
withcoords
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withgeojsonbound"
,
16
))
withgeojsonbounds
=
true
;
withgeojsonbounds
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withgeojsoncollection"
,
21
))
withgeojsoncollection
=
true
;
withgeojsoncollection
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"withgeo"
,
7
)
||
!
strcasecmp
(
arg
,
"geojson"
)
||
!
strcasecmp
(
arg
,
"json"
)
||
!
strcasecmp
(
arg
,
"withjson"
))
withgeojson
=
true
;
withgeojson
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"noprop"
,
6
)
||
!
strncasecmp
(
arg
,
"withoutprop"
,
11
))
noproperties
=
true
;
noproperties
=
1
;
else
if
(
!
strncasecmp
(
arg
,
"asc"
,
3
)
||
!
strncasecmp
(
arg
,
"sort"
,
4
))
sort
=
SORT_ASC
;
...
...
@@ -470,7 +471,7 @@ static void geoRadiusGeneric(redisClient *c, int type) {
}
}
bool
withgeo
=
withgeojsonbounds
||
withgeojsoncollection
||
withgeojson
;
int
withgeo
=
withgeojsonbounds
||
withgeojsoncollection
||
withgeojson
;
/* Get all neighbor geohash boxes for our radius search */
GeoHashRadius
georadius
=
...
...
@@ -617,9 +618,9 @@ void geoDecodeCommand(redisClient *c) {
NULL
)
!=
REDIS_OK
)
return
;
bool
withgeojson
=
false
;
int
withgeojson
=
0
;
if
(
c
->
argc
==
3
)
withgeojson
=
true
;
withgeojson
=
1
;
GeoHashArea
area
;
geohash
.
step
=
GEO_STEP_MAX
;
...
...
@@ -665,12 +666,12 @@ void geoEncodeCommand(redisClient *c) {
* - AND / OR -
* optional: [geojson] */
bool
withgeojson
=
false
;
int
withgeojson
=
0
;
for
(
int
i
=
3
;
i
<
c
->
argc
;
i
++
)
{
char
*
arg
=
c
->
argv
[
i
]
->
ptr
;
if
(
!
strncasecmp
(
arg
,
"withgeo"
,
7
)
||
!
strcasecmp
(
arg
,
"geojson"
)
||
!
strcasecmp
(
arg
,
"json"
)
||
!
strcasecmp
(
arg
,
"withjson"
))
{
withgeojson
=
true
;
withgeojson
=
1
;
break
;
}
}
...
...
src/zset.c
浏览文件 @
f193b3ca
...
...
@@ -13,13 +13,13 @@ int zslValueLteMax(double value, zrangespec *spec);
* ==================================================================== */
/* zset access is mostly a copy/paste from zscoreCommand() */
bool
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
)
{
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
)
{
if
(
!
zobj
||
!
member
)
return
false
;
return
0
;
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
if
(
zzlFind
(
zobj
->
ptr
,
member
,
score
)
==
NULL
)
return
false
;
return
0
;
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_SKIPLIST
)
{
zset
*
zs
=
zobj
->
ptr
;
dictEntry
*
de
;
...
...
@@ -29,11 +29,11 @@ bool zsetScore(robj *zobj, robj *member, double *score) {
if
(
de
!=
NULL
)
{
*
score
=
*
(
double
*
)
dictGetVal
(
de
);
}
else
return
false
;
return
0
;
}
else
{
return
false
;
return
0
;
}
return
true
;
return
1
;
}
/* Largely extracted from genericZrangebyscoreCommand() in t_zset.c */
...
...
src/zset.h
浏览文件 @
f193b3ca
...
...
@@ -2,7 +2,6 @@
#define __ZSET_H__
#include "redis.h"
#include <stdbool.h>
#define ZR_LONG 1
#define ZR_STRING 2
...
...
@@ -17,7 +16,7 @@ struct zipresult {
};
/* Redis DB Access */
bool
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
);
int
zsetScore
(
robj
*
zobj
,
robj
*
member
,
double
*
score
);
list
*
geozrangebyscore
(
robj
*
zobj
,
double
min
,
double
max
,
int
limit
);
/* New list operation: append one list to another */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录