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
3e9c20f6
Commit
3e9c20f6
authored
Jun 05, 2016
by
Pierre Chapuis
Browse files
untangle LINSERT and {L,R}PUSHX implementations
parent
550fa7e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/t_list.c
View file @
3e9c20f6
...
@@ -232,68 +232,73 @@ void rpushCommand(client *c) {
...
@@ -232,68 +232,73 @@ void rpushCommand(client *c) {
pushGenericCommand
(
c
,
LIST_TAIL
);
pushGenericCommand
(
c
,
LIST_TAIL
);
}
}
void
pushxGenericCommand
(
client
*
c
,
robj
*
refval
,
robj
*
val
,
int
where
)
{
void
pushxGenericCommand
(
client
*
c
,
int
where
)
{
robj
*
subject
;
robj
*
subject
;
listTypeIterator
*
iter
;
listTypeEntry
entry
;
int
inserted
=
0
;
if
((
subject
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
if
((
subject
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
subject
,
OBJ_LIST
))
return
;
checkType
(
c
,
subject
,
OBJ_LIST
))
return
;
if
(
refval
!=
NULL
)
{
char
*
event
=
(
where
==
LIST_HEAD
)
?
"lpush"
:
"rpush"
;
/* Seek refval from head to tail */
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
iter
=
listTypeInitIterator
(
subject
,
0
,
LIST_TAIL
);
listTypePush
(
subject
,
c
->
argv
[
2
],
where
);
while
(
listTypeNext
(
iter
,
&
entry
))
{
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
if
(
listTypeEqual
(
&
entry
,
refval
))
{
notifyKeyspaceEvent
(
NOTIFY_LIST
,
event
,
c
->
argv
[
1
],
c
->
db
->
id
);
listTypeInsert
(
&
entry
,
val
,
where
);
server
.
dirty
++
;
inserted
=
1
;
break
;
}
}
listTypeReleaseIterator
(
iter
);
if
(
inserted
)
{
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
notifyKeyspaceEvent
(
NOTIFY_LIST
,
"linsert"
,
c
->
argv
[
1
],
c
->
db
->
id
);
server
.
dirty
++
;
}
else
{
/* Notify client of a failed insert */
addReply
(
c
,
shared
.
cnegone
);
return
;
}
}
else
{
char
*
event
=
(
where
==
LIST_HEAD
)
?
"lpush"
:
"rpush"
;
listTypePush
(
subject
,
val
,
where
);
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
notifyKeyspaceEvent
(
NOTIFY_LIST
,
event
,
c
->
argv
[
1
],
c
->
db
->
id
);
server
.
dirty
++
;
}
addReplyLongLong
(
c
,
listTypeLength
(
subject
));
addReplyLongLong
(
c
,
listTypeLength
(
subject
));
}
}
void
lpushxCommand
(
client
*
c
)
{
void
lpushxCommand
(
client
*
c
)
{
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
pushxGenericCommand
(
c
,
LIST_HEAD
);
pushxGenericCommand
(
c
,
NULL
,
c
->
argv
[
2
],
LIST_HEAD
);
}
}
void
rpushxCommand
(
client
*
c
)
{
void
rpushxCommand
(
client
*
c
)
{
c
->
argv
[
2
]
=
tryObjectEncoding
(
c
->
argv
[
2
]);
pushxGenericCommand
(
c
,
LIST_TAIL
);
pushxGenericCommand
(
c
,
NULL
,
c
->
argv
[
2
],
LIST_TAIL
);
}
}
void
linsertCommand
(
client
*
c
)
{
void
linsertCommand
(
client
*
c
)
{
int
where
;
robj
*
subject
;
listTypeIterator
*
iter
;
listTypeEntry
entry
;
int
inserted
=
0
;
c
->
argv
[
4
]
=
tryObjectEncoding
(
c
->
argv
[
4
]);
c
->
argv
[
4
]
=
tryObjectEncoding
(
c
->
argv
[
4
]);
if
(
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"after"
)
==
0
)
{
if
(
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"after"
)
==
0
)
{
pushxGenericCommand
(
c
,
c
->
argv
[
3
],
c
->
argv
[
4
],
LIST_TAIL
)
;
where
=
LIST_TAIL
;
}
else
if
(
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"before"
)
==
0
)
{
}
else
if
(
strcasecmp
(
c
->
argv
[
2
]
->
ptr
,
"before"
)
==
0
)
{
pushxGenericCommand
(
c
,
c
->
argv
[
3
],
c
->
argv
[
4
],
LIST_HEAD
)
;
where
=
LIST_HEAD
;
}
else
{
}
else
{
addReply
(
c
,
shared
.
syntaxerr
);
addReply
(
c
,
shared
.
syntaxerr
);
return
;
}
if
((
subject
=
lookupKeyWriteOrReply
(
c
,
c
->
argv
[
1
],
shared
.
czero
))
==
NULL
||
checkType
(
c
,
subject
,
OBJ_LIST
))
return
;
/* Seek pivot from head to tail */
iter
=
listTypeInitIterator
(
subject
,
0
,
LIST_TAIL
);
while
(
listTypeNext
(
iter
,
&
entry
))
{
if
(
listTypeEqual
(
&
entry
,
c
->
argv
[
3
]))
{
listTypeInsert
(
&
entry
,
c
->
argv
[
4
],
where
);
inserted
=
1
;
break
;
}
}
}
listTypeReleaseIterator
(
iter
);
if
(
inserted
)
{
signalModifiedKey
(
c
->
db
,
c
->
argv
[
1
]);
notifyKeyspaceEvent
(
NOTIFY_LIST
,
"linsert"
,
c
->
argv
[
1
],
c
->
db
->
id
);
server
.
dirty
++
;
}
else
{
/* Notify client of a failed insert */
addReply
(
c
,
shared
.
cnegone
);
return
;
}
addReplyLongLong
(
c
,
listTypeLength
(
subject
));
}
}
void
llenCommand
(
client
*
c
)
{
void
llenCommand
(
client
*
c
)
{
...
...
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