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
5bf5fd24
Commit
5bf5fd24
authored
Apr 25, 2016
by
antirez
Browse files
Modules: a few fixes for the zset iterator.
parent
33e1231e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
5bf5fd24
...
...
@@ -1366,7 +1366,7 @@ int RM_ZsetRangeNext(RedisModuleKey *key) {
return
0
;
}
next
=
saved_next
;
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_
SCORE
)
{
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_
LEX
)
{
if
(
!
zzlLexValueLteMax
(
next
,
&
key
->
zlrs
))
{
key
->
zer
=
1
;
return
0
;
...
...
@@ -1429,7 +1429,7 @@ int RM_ZsetRangePrev(RedisModuleKey *key) {
return
0
;
}
prev
=
saved_prev
;
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_
SCORE
)
{
}
else
if
(
key
->
ztype
==
REDISMODULE_ZSET_RANGE_
LEX
)
{
if
(
!
zzlLexValueGteMin
(
prev
,
&
key
->
zlrs
))
{
key
->
zer
=
1
;
return
0
;
...
...
src/modules/helloworld.c
View file @
5bf5fd24
...
...
@@ -387,7 +387,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
* The command will return all the sorted set items that are lexicographically
* between the specified range (using the same format as ZRANGEBYLEX)
* and having an age between min_age and max_age. */
int
Hello
Zsum
Range_RedisCommand
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
int
Hello
Lex
Range_RedisCommand
(
RedisModuleCtx
*
ctx
,
RedisModuleString
**
argv
,
int
argc
)
{
RedisModule_AutoMemory
(
ctx
);
/* Use automatic memory management. */
if
(
argc
!=
6
)
return
RedisModule_WrongArity
(
ctx
);
...
...
@@ -398,9 +398,12 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
return
RedisModule_ReplyWithError
(
ctx
,
REDISMODULE_ERRORMSG_WRONGTYPE
);
}
RedisModule_ReplyWithArray
(
ctx
,
REDISMODULE_POSTPONED_ARRAY_LEN
);
RedisModule_ZsetFirstInLexRange
(
key
,
argv
[
2
],
argv
[
3
]);
if
(
RedisModule_ZsetFirstInLexRange
(
key
,
argv
[
2
],
argv
[
3
])
!=
REDISMODULE_OK
)
{
return
RedisModule_ReplyWithError
(
ctx
,
"invalid range"
);
}
int
arraylen
=
0
;
RedisModule_ReplyWithArray
(
ctx
,
REDISMODULE_POSTPONED_ARRAY_LEN
);
while
(
!
RedisModule_ZsetRangeEndReached
(
key
))
{
double
score
;
RedisModuleString
*
ele
=
RedisModule_ZsetRangeCurrentElement
(
key
,
&
score
);
...
...
@@ -410,7 +413,7 @@ int HelloZsumRange_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, i
arraylen
++
;
}
RedisModule_ZsetRangeStop
(
key
);
RedisModule_SetArrayLength
(
ctx
,
arraylen
);
RedisModule_
Reply
SetArrayLength
(
ctx
,
arraylen
);
RedisModule_CloseKey
(
key
);
return
REDISMODULE_OK
;
}
...
...
@@ -473,5 +476,9 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx) {
HelloZsumRange_RedisCommand
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
if
(
RedisModule_CreateCommand
(
ctx
,
"hello.lexrange"
,
HelloLexRange_RedisCommand
)
==
REDISMODULE_ERR
)
return
REDISMODULE_ERR
;
return
REDISMODULE_OK
;
}
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