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
0f62e177
Commit
0f62e177
authored
May 31, 2010
by
Pieter Noordhuis
Browse files
update RPOPLPUSH to support dual encoding
parent
be02a7c0
Changes
1
Show whitespace changes
Inline
Side-by-side
redis.c
View file @
0f62e177
...
@@ -4805,8 +4805,9 @@ static robj *lPop(robj *subject, int where) {
...
@@ -4805,8 +4805,9 @@ static robj *lPop(robj *subject, int where) {
}
else
{
}
else
{
value
=
createStringObjectFromLongLong
(
vval
);
value
=
createStringObjectFromLongLong
(
vval
);
}
}
}
/* We only need to delete an element when it exists */
subject
->
ptr
=
ziplistDelete
(
subject
->
ptr
,
&
p
);
subject
->
ptr
=
ziplistDelete
(
subject
->
ptr
,
&
p
);
}
}
else
if
(
subject
->
encoding
==
REDIS_ENCODING_LIST
)
{
}
else
if
(
subject
->
encoding
==
REDIS_ENCODING_LIST
)
{
list
*
list
=
subject
->
ptr
;
list
*
list
=
subject
->
ptr
;
listNode
*
ln
;
listNode
*
ln
;
...
@@ -5246,47 +5247,38 @@ static void lremCommand(redisClient *c) {
...
@@ -5246,47 +5247,38 @@ static void lremCommand(redisClient *c) {
* as well. This command was originally proposed by Ezra Zygmuntowicz.
* as well. This command was originally proposed by Ezra Zygmuntowicz.
*/
*/
static
void
rpoplpushcommand
(
redisClient
*
c
)
{
static
void
rpoplpushcommand
(
redisClient
*
c
)
{
robj
*
sobj
;
robj
*
sobj
,
*
value
;
list
*
srclist
;
listNode
*
ln
;
if
((
sobj
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
if
((
sobj
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
nullbulk
))
==
NULL
||
checkType
(
c
,
sobj
,
REDIS_LIST
))
return
;
checkType
(
c
,
sobj
,
REDIS_LIST
))
return
;
srclist
=
sobj
->
ptr
;
ln
=
listLast
(
srclist
);
if
(
l
n
==
NULL
)
{
if
(
l
Length
(
sobj
)
==
0
)
{
addReply
(
c
,
shared
.
nullbulk
);
addReply
(
c
,
shared
.
nullbulk
);
}
else
{
}
else
{
robj
*
dobj
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
2
]);
robj
*
dobj
=
lookupKeyWrite
(
c
->
db
,
c
->
argv
[
2
]);
robj
*
ele
=
listNodeValue
(
ln
);
if
(
dobj
&&
checkType
(
c
,
dobj
,
REDIS_LIST
))
return
;
list
*
dstlist
;
value
=
lPop
(
sobj
,
REDIS_TAIL
);
if
(
dobj
&&
dobj
->
type
!=
REDIS_LIST
)
{
addReply
(
c
,
shared
.
wrongtypeerr
);
return
;
}
/* Add the element to the target list (unless it's directly
/* Add the element to the target list (unless it's directly
* passed to some BLPOP-ing client */
* passed to some BLPOP-ing client */
if
(
!
handleClientsWaitingListPush
(
c
,
c
->
argv
[
2
],
ele
))
{
if
(
!
handleClientsWaitingListPush
(
c
,
c
->
argv
[
2
],
value
))
{
if
(
dobj
==
NULL
)
{
/* Create the list if the key does not exist */
/* Create the list if the key does not exist */
dobj
=
createListObject
();
if
(
!
dobj
)
{
dobj
=
createObject
(
REDIS_LIST
,
ziplistNew
());
dobj
->
encoding
=
REDIS_ENCODING_ZIPLIST
;
dictAdd
(
c
->
db
->
dict
,
c
->
argv
[
2
],
dobj
);
dictAdd
(
c
->
db
->
dict
,
c
->
argv
[
2
],
dobj
);
incrRefCount
(
c
->
argv
[
2
]);
incrRefCount
(
c
->
argv
[
2
]);
}
}
dstlist
=
dobj
->
ptr
;
lPush
(
dobj
,
value
,
REDIS_HEAD
);
listAddNodeHead
(
dstlist
,
ele
);
incrRefCount
(
ele
);
}
}
/* Send the element to the client as reply as well */
/* Send the element to the client as reply as well */
addReplyBulk
(
c
,
ele
);
addReplyBulk
(
c
,
value
);
/* lPop returns an object with its refcount incremented */
decrRefCount
(
value
);
/* Finally remove the element from the source list */
/* Delete the source list when it is empty */
listDelNode
(
srclist
,
ln
);
if
(
lLength
(
sobj
)
==
0
)
deleteKey
(
c
->
db
,
c
->
argv
[
1
]);
if
(
listLength
(
srclist
)
==
0
)
deleteKey
(
c
->
db
,
c
->
argv
[
1
]);
server
.
dirty
++
;
server
.
dirty
++
;
}
}
}
}
...
...
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