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
6eeeda39
Commit
6eeeda39
authored
Apr 19, 2016
by
antirez
Browse files
Modules: sorted set iterators WIP #2.
parent
eac5a13c
Changes
3
Show whitespace changes
Inline
Side-by-side
src/module.c
View file @
6eeeda39
...
@@ -1075,6 +1075,17 @@ RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score
...
@@ -1075,6 +1075,17 @@ RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score
* does not include any item at all. */
* does not include any item at all. */
int RM_ZsetRangeNext(RedisModuleKey *key) {
int RM_ZsetRangeNext(RedisModuleKey *key) {
if (!key->zr || !key->zcurrent) return 0; /* No active iterator. */
if (!key->zr || !key->zcurrent) return 0; /* No active iterator. */
zrangespec zrs;
/* Convert to core range structure. */
RedisModuleZsetRange *zr = key->zr;
if (zr->type == REDISMODULE_ZSET_RANGE_SCORE) {
zrs.min = zr->score_start;
zrs.max = zr->score_end;
zrs.minex = (zr->flags & REDISMODULE_ZSET_RANGE_START_EX) != 0;
zrs.maxex = (zr->flags & REDISMODULE_ZSET_RANGE_END_EX) != 0;
}
if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
unsigned char *zl = key->value->ptr;
unsigned char *zl = key->value->ptr;
unsigned char *eptr = key->zcurrent;
unsigned char *eptr = key->zcurrent;
...
@@ -1085,8 +1096,19 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
...
@@ -1085,8 +1096,19 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
key->zer = 1;
key->zer = 1;
return 0;
return 0;
} else {
} else {
/* TODO: check if we are in range. */
/* Fetch the next element score for the
key
->
zcurrent
=
next
;
* range check. */
unsigned char *saved_next = next;
next = ziplistNext(zl,next); /* Skip next element. */
double score = zzlGetScore(next); /* Obtain the next score. */
/* Are we still within the range? */
if (zr->type == REDISMODULE_ZSET_RANGE_SCORE &&
!zslValueLteMax(score,&zrs))
{
key->zer = 1;
return 0;
}
key->zcurrent = saved_next;
return 1;
return 1;
}
}
} else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
} else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
...
@@ -1095,7 +1117,13 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
...
@@ -1095,7 +1117,13 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
key->zer = 1;
key->zer = 1;
return 0;
return 0;
} else {
} else {
/* TODO: check if we are in range. */
/* Are we still within the range? */
if (zr->type == REDISMODULE_ZSET_RANGE_SCORE &&
!zslValueLteMax(ln->score,&zrs))
{
key->zer = 1;
return 0;
}
key->zcurrent = next;
key->zcurrent = next;
return 1;
return 1;
}
}
...
...
src/server.h
View file @
6eeeda39
...
@@ -1344,6 +1344,8 @@ int zsetAdd(robj *zobj, double score, sds ele, int *flags, double *newscore);
...
@@ -1344,6 +1344,8 @@ int zsetAdd(robj *zobj, double score, sds ele, int *flags, double *newscore);
long
zsetRank
(
robj
*
zobj
,
sds
ele
,
int
reverse
);
long
zsetRank
(
robj
*
zobj
,
sds
ele
,
int
reverse
);
int
zsetDel
(
robj
*
zobj
,
sds
ele
);
int
zsetDel
(
robj
*
zobj
,
sds
ele
);
sds
ziplistGetObject
(
unsigned
char
*
sptr
);
sds
ziplistGetObject
(
unsigned
char
*
sptr
);
int
zslValueGteMin
(
double
value
,
zrangespec
*
spec
);
int
zslValueLteMax
(
double
value
,
zrangespec
*
spec
);
/* Core functions */
/* Core functions */
int
freeMemoryIfNeeded
(
void
);
int
freeMemoryIfNeeded
(
void
);
...
...
src/t_zset.c
View file @
6eeeda39
...
@@ -244,7 +244,7 @@ int zslDelete(zskiplist *zsl, double score, sds ele, zskiplistNode **node) {
...
@@ -244,7 +244,7 @@ int zslDelete(zskiplist *zsl, double score, sds ele, zskiplistNode **node) {
return
0
;
/* not found */
return
0
;
/* not found */
}
}
static
int
zslValueGteMin
(
double
value
,
zrangespec
*
spec
)
{
int
zslValueGteMin
(
double
value
,
zrangespec
*
spec
)
{
return
spec
->
minex
?
(
value
>
spec
->
min
)
:
(
value
>=
spec
->
min
);
return
spec
->
minex
?
(
value
>
spec
->
min
)
:
(
value
>=
spec
->
min
);
}
}
...
...
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