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
9ae6b0be
Commit
9ae6b0be
authored
May 30, 2010
by
Pieter Noordhuis
Browse files
support dual encoding in LTRIM
parent
a6dd455b
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
9ae6b0be
...
@@ -5087,8 +5087,7 @@ static void ltrimCommand(redisClient *c) {
...
@@ -5087,8 +5087,7 @@ static void ltrimCommand(redisClient *c) {
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL ||
if ((o = lookupKeyWriteOrReply(c,c->argv[1],shared.ok)) == NULL ||
checkType(c,o,REDIS_LIST)) return;
checkType(c,o,REDIS_LIST)) return;
list = o->ptr;
llen = lLength(o);
llen = listLength(list);
/* convert negative indexes */
/* convert negative indexes */
if (start < 0) start = llen+start;
if (start < 0) start = llen+start;
...
@@ -5108,15 +5107,23 @@ static void ltrimCommand(redisClient *c) {
...
@@ -5108,15 +5107,23 @@ static void ltrimCommand(redisClient *c) {
}
}
/* Remove list elements to perform the trim */
/* Remove list elements to perform the trim */
for (j = 0; j < ltrim; j++) {
if (o->encoding == REDIS_ENCODING_ZIPLIST) {
ln = listFirst(list);
o->ptr = ziplistDeleteRange(o->ptr,0,ltrim);
listDelNode(list,ln);
o->ptr = ziplistDeleteRange(o->ptr,-rtrim,rtrim);
}
} else if (o->encoding == REDIS_ENCODING_LIST) {
for (j = 0; j < rtrim; j++) {
list = o->ptr;
ln = listLast(list);
for (j = 0; j < ltrim; j++) {
listDelNode(list,ln);
ln = listFirst(list);
listDelNode(list,ln);
}
for (j = 0; j < rtrim; j++) {
ln = listLast(list);
listDelNode(list,ln);
}
} else {
redisPanic("Unknown list encoding");
}
}
if (l
ist
Length(
list
) == 0) deleteKey(c->db,c->argv[1]);
if (lLength(
o
) == 0) deleteKey(c->db,c->argv[1]);
server.dirty++;
server.dirty++;
addReply(c,shared.ok);
addReply(c,shared.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