Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
63b7b7fb
Commit
63b7b7fb
authored
Mar 09, 2011
by
Pieter Noordhuis
Browse files
Support dual encoding for ZREMRANGEBYRANK
parent
5d1b4fb6
Changes
1
Show whitespace changes
Inline
Side-by-side
src/t_zset.c
View file @
63b7b7fb
...
@@ -666,6 +666,14 @@ unsigned long zzlDeleteRangeByScore(robj *zobj, zrangespec range) {
...
@@ -666,6 +666,14 @@ unsigned long zzlDeleteRangeByScore(robj *zobj, zrangespec range) {
return
deleted
;
return
deleted
;
}
}
/* Delete all the elements with rank between start and end from the skiplist.
* Start and end are inclusive. Note that start and end need to be 1-based */
unsigned
long
zzlDeleteRangeByRank
(
robj
*
zobj
,
unsigned
int
start
,
unsigned
int
end
)
{
unsigned
int
num
=
(
end
-
start
)
+
1
;
zobj
->
ptr
=
ziplistDeleteRange
(
zobj
->
ptr
,
2
*
(
start
-
1
),
2
*
num
);
return
num
;
}
/*-----------------------------------------------------------------------------
/*-----------------------------------------------------------------------------
* Common sorted set API
* Common sorted set API
*----------------------------------------------------------------------------*/
*----------------------------------------------------------------------------*/
...
@@ -892,22 +900,21 @@ void zremrangebyscoreCommand(redisClient *c) {
...
@@ -892,22 +900,21 @@ void zremrangebyscoreCommand(redisClient *c) {
}
}
void
zremrangebyrankCommand
(
redisClient
*
c
)
{
void
zremrangebyrankCommand
(
redisClient
*
c
)
{
robj
*
key
=
c
->
argv
[
1
];
robj
*
zobj
;
long
start
;
long
start
;
long
end
;
long
end
;
int
llen
;
int
llen
;
long
deleted
;
unsigned
long
deleted
;
robj
*
zsetobj
;
zset
*
zs
;
if
((
getLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
start
,
NULL
)
!=
REDIS_OK
)
||
if
((
getLongFromObjectOrReply
(
c
,
c
->
argv
[
2
],
&
start
,
NULL
)
!=
REDIS_OK
)
||
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
end
,
NULL
)
!=
REDIS_OK
))
return
;
(
getLongFromObjectOrReply
(
c
,
c
->
argv
[
3
],
&
end
,
NULL
)
!=
REDIS_OK
))
return
;
if
((
zsetobj
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
if
((
zobj
=
lookupKeyWriteOrReply
(
c
,
key
,
shared
.
czero
))
==
NULL
||
checkType
(
c
,
zsetobj
,
REDIS_ZSET
))
return
;
checkType
(
c
,
zobj
,
REDIS_ZSET
))
return
;
zs
=
zsetobj
->
ptr
;
llen
=
zs
->
zsl
->
length
;
/* convert negative indexes */
/* Sanitize indexes. */
llen
=
zsLength
(
zobj
);
if
(
start
<
0
)
start
=
llen
+
start
;
if
(
start
<
0
)
start
=
llen
+
start
;
if
(
end
<
0
)
end
=
llen
+
end
;
if
(
end
<
0
)
end
=
llen
+
end
;
if
(
start
<
0
)
start
=
0
;
if
(
start
<
0
)
start
=
0
;
...
@@ -920,14 +927,23 @@ void zremrangebyrankCommand(redisClient *c) {
...
@@ -920,14 +927,23 @@ void zremrangebyrankCommand(redisClient *c) {
}
}
if
(
end
>=
llen
)
end
=
llen
-
1
;
if
(
end
>=
llen
)
end
=
llen
-
1
;
/* increment start and end because zsl*Rank functions
if
(
zobj
->
encoding
==
REDIS_ENCODING_ZIPLIST
)
{
* use 1-based rank */
/* Correct for 1-based rank. */
deleted
=
zzlDeleteRangeByRank
(
zobj
,
start
+
1
,
end
+
1
);
}
else
if
(
zobj
->
encoding
==
REDIS_ENCODING_RAW
)
{
zset
*
zs
=
zobj
->
ptr
;
/* Correct for 1-based rank. */
deleted
=
zslDeleteRangeByRank
(
zs
->
zsl
,
start
+
1
,
end
+
1
,
zs
->
dict
);
deleted
=
zslDeleteRangeByRank
(
zs
->
zsl
,
start
+
1
,
end
+
1
,
zs
->
dict
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
htNeedsResize
(
zs
->
dict
))
dictResize
(
zs
->
dict
);
if
(
dictSize
(
zs
->
dict
)
==
0
)
dbDelete
(
c
->
db
,
c
->
argv
[
1
]);
if
(
dictSize
(
zs
->
dict
)
==
0
)
dbDelete
(
c
->
db
,
key
);
if
(
deleted
)
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
}
else
{
redisPanic
(
"Unknown sorted set encoding"
);
}
if
(
deleted
)
signalModifiedKey
(
c
->
db
,
key
);
server
.
dirty
+=
deleted
;
server
.
dirty
+=
deleted
;
addReplyLongLong
(
c
,
deleted
);
addReplyLongLong
(
c
,
deleted
);
}
}
typedef
struct
{
typedef
struct
{
...
...
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