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
db3ade22
Commit
db3ade22
authored
Apr 21, 2016
by
antirez
Browse files
Modules: zset lex iterator #2.
parent
2b04f86a
Changes
3
Show whitespace changes
Inline
Side-by-side
src/module.c
View file @
db3ade22
...
@@ -1286,6 +1286,11 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
...
@@ -1286,6 +1286,11 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
return
0
;
return
0
;
}
}
next
=
saved_next
;
next
=
saved_next
;
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_SCORE
)
{
if
(
!
zzlLexValueLteMax
(
next
,
&
key
->
zlrs
))
{
key
->
zer
=
1
;
return
0
;
}
}
}
key
->
zcurrent
=
next
;
key
->
zcurrent
=
next
;
return
1
;
return
1
;
...
@@ -1302,6 +1307,11 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
...
@@ -1302,6 +1307,11 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
{
{
key
->
zer
=
1
;
key
->
zer
=
1
;
return
0
;
return
0
;
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_SCORE
)
{
if
(
!
zslLexValueLteMax
(
ln
->
ele
,
&
key
->
zlrs
))
{
key
->
zer
=
1
;
return
0
;
}
}
}
key
->
zcurrent
=
next
;
key
->
zcurrent
=
next
;
return
1
;
return
1
;
...
@@ -1339,6 +1349,11 @@ int RM_ZsetRangePrev(RedisModuleKey *key) {
...
@@ -1339,6 +1349,11 @@ int RM_ZsetRangePrev(RedisModuleKey *key) {
return
0
;
return
0
;
}
}
prev
=
saved_prev
;
prev
=
saved_prev
;
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_SCORE
)
{
if
(
!
zzlLexValueGteMin
(
prev
,
&
key
->
zlrs
))
{
key
->
zer
=
1
;
return
0
;
}
}
}
key
->
zcurrent
=
prev
;
key
->
zcurrent
=
prev
;
return
1
;
return
1
;
...
@@ -1355,6 +1370,11 @@ int RM_ZsetRangePrev(RedisModuleKey *key) {
...
@@ -1355,6 +1370,11 @@ int RM_ZsetRangePrev(RedisModuleKey *key) {
{
{
key
->
zer
=
1
;
key
->
zer
=
1
;
return
0
;
return
0
;
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_SCORE
)
{
if
(
!
zslLexValueGteMin
(
prev
->
ele
,
&
key
->
zlrs
))
{
key
->
zer
=
1
;
return
0
;
}
}
}
key
->
zcurrent
=
prev
;
key
->
zcurrent
=
prev
;
return
1
;
return
1
;
...
...
src/server.h
View file @
db3ade22
...
@@ -1353,6 +1353,10 @@ unsigned char *zzlFirstInLexRange(unsigned char *zl, zlexrangespec *range);
...
@@ -1353,6 +1353,10 @@ unsigned char *zzlFirstInLexRange(unsigned char *zl, zlexrangespec *range);
unsigned
char
*
zzlLastInLexRange
(
unsigned
char
*
zl
,
zlexrangespec
*
range
);
unsigned
char
*
zzlLastInLexRange
(
unsigned
char
*
zl
,
zlexrangespec
*
range
);
zskiplistNode
*
zslFirstInLexRange
(
zskiplist
*
zsl
,
zlexrangespec
*
range
);
zskiplistNode
*
zslFirstInLexRange
(
zskiplist
*
zsl
,
zlexrangespec
*
range
);
zskiplistNode
*
zslLastInLexRange
(
zskiplist
*
zsl
,
zlexrangespec
*
range
);
zskiplistNode
*
zslLastInLexRange
(
zskiplist
*
zsl
,
zlexrangespec
*
range
);
int
zzlLexValueGteMin
(
unsigned
char
*
p
,
zlexrangespec
*
spec
);
int
zzlLexValueLteMax
(
unsigned
char
*
p
,
zlexrangespec
*
spec
);
int
zslLexValueGteMin
(
sds
value
,
zlexrangespec
*
spec
);
int
zslLexValueLteMax
(
sds
value
,
zlexrangespec
*
spec
);
/* Core functions */
/* Core functions */
int
freeMemoryIfNeeded
(
void
);
int
freeMemoryIfNeeded
(
void
);
...
...
src/t_zset.c
View file @
db3ade22
...
@@ -63,8 +63,8 @@
...
@@ -63,8 +63,8 @@
* Skiplist implementation of the low level API
* Skiplist implementation of the low level API
*----------------------------------------------------------------------------*/
*----------------------------------------------------------------------------*/
static
int
zslLexValueGteMin
(
sds
value
,
zlexrangespec
*
spec
);
int
zslLexValueGteMin
(
sds
value
,
zlexrangespec
*
spec
);
static
int
zslLexValueLteMax
(
sds
value
,
zlexrangespec
*
spec
);
int
zslLexValueLteMax
(
sds
value
,
zlexrangespec
*
spec
);
/* Create a skiplist node with the specified number of levels.
/* Create a skiplist node with the specified number of levels.
* The SDS string 'ele' is referenced by the node after the call. */
* The SDS string 'ele' is referenced by the node after the call. */
...
@@ -580,13 +580,13 @@ int sdscmplex(sds a, sds b) {
...
@@ -580,13 +580,13 @@ int sdscmplex(sds a, sds b) {
return
sdscmp
(
a
,
b
);
return
sdscmp
(
a
,
b
);
}
}
static
int
zslLexValueGteMin
(
sds
value
,
zlexrangespec
*
spec
)
{
int
zslLexValueGteMin
(
sds
value
,
zlexrangespec
*
spec
)
{
return
spec
->
minex
?
return
spec
->
minex
?
(
sdscmplex
(
value
,
spec
->
min
)
>
0
)
:
(
sdscmplex
(
value
,
spec
->
min
)
>
0
)
:
(
sdscmplex
(
value
,
spec
->
min
)
>=
0
);
(
sdscmplex
(
value
,
spec
->
min
)
>=
0
);
}
}
static
int
zslLexValueLteMax
(
sds
value
,
zlexrangespec
*
spec
)
{
int
zslLexValueLteMax
(
sds
value
,
zlexrangespec
*
spec
)
{
return
spec
->
maxex
?
return
spec
->
maxex
?
(
sdscmplex
(
value
,
spec
->
max
)
<
0
)
:
(
sdscmplex
(
value
,
spec
->
max
)
<
0
)
:
(
sdscmplex
(
value
,
spec
->
max
)
<=
0
);
(
sdscmplex
(
value
,
spec
->
max
)
<=
0
);
...
@@ -852,14 +852,14 @@ unsigned char *zzlLastInRange(unsigned char *zl, zrangespec *range) {
...
@@ -852,14 +852,14 @@ unsigned char *zzlLastInRange(unsigned char *zl, zrangespec *range) {
return
NULL
;
return
NULL
;
}
}
static
int
zzlLexValueGteMin
(
unsigned
char
*
p
,
zlexrangespec
*
spec
)
{
int
zzlLexValueGteMin
(
unsigned
char
*
p
,
zlexrangespec
*
spec
)
{
sds
value
=
ziplistGetObject
(
p
);
sds
value
=
ziplistGetObject
(
p
);
int
res
=
zslLexValueGteMin
(
value
,
spec
);
int
res
=
zslLexValueGteMin
(
value
,
spec
);
sdsfree
(
value
);
sdsfree
(
value
);
return
res
;
return
res
;
}
}
static
int
zzlLexValueLteMax
(
unsigned
char
*
p
,
zlexrangespec
*
spec
)
{
int
zzlLexValueLteMax
(
unsigned
char
*
p
,
zlexrangespec
*
spec
)
{
sds
value
=
ziplistGetObject
(
p
);
sds
value
=
ziplistGetObject
(
p
);
int
res
=
zslLexValueLteMax
(
value
,
spec
);
int
res
=
zslLexValueLteMax
(
value
,
spec
);
sdsfree
(
value
);
sdsfree
(
value
);
...
...
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