mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
untangle LINSERT and {L,R}PUSHX implementations
This commit is contained in:
parent
550fa7e14f
commit
3e9c20f63b
73
src/t_list.c
73
src/t_list.c
@ -232,21 +232,55 @@ void rpushCommand(client *c) {
|
||||
pushGenericCommand(c,LIST_TAIL);
|
||||
}
|
||||
|
||||
void pushxGenericCommand(client *c, robj *refval, robj *val, int where) {
|
||||
void pushxGenericCommand(client *c, int where) {
|
||||
robj *subject;
|
||||
|
||||
if ((subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||
checkType(c,subject,OBJ_LIST)) return;
|
||||
|
||||
char *event = (where == LIST_HEAD) ? "lpush" : "rpush";
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
listTypePush(subject,c->argv[2],where);
|
||||
signalModifiedKey(c->db,c->argv[1]);
|
||||
notifyKeyspaceEvent(NOTIFY_LIST,event,c->argv[1],c->db->id);
|
||||
server.dirty++;
|
||||
|
||||
addReplyLongLong(c,listTypeLength(subject));
|
||||
}
|
||||
|
||||
void lpushxCommand(client *c) {
|
||||
pushxGenericCommand(c,LIST_HEAD);
|
||||
}
|
||||
|
||||
void rpushxCommand(client *c) {
|
||||
pushxGenericCommand(c,LIST_TAIL);
|
||||
}
|
||||
|
||||
void linsertCommand(client *c) {
|
||||
int where;
|
||||
robj *subject;
|
||||
listTypeIterator *iter;
|
||||
listTypeEntry entry;
|
||||
int inserted = 0;
|
||||
|
||||
c->argv[4] = tryObjectEncoding(c->argv[4]);
|
||||
if (strcasecmp(c->argv[2]->ptr,"after") == 0) {
|
||||
where = LIST_TAIL;
|
||||
} else if (strcasecmp(c->argv[2]->ptr,"before") == 0) {
|
||||
where = LIST_HEAD;
|
||||
} else {
|
||||
addReply(c,shared.syntaxerr);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((subject = lookupKeyWriteOrReply(c,c->argv[1],shared.czero)) == NULL ||
|
||||
checkType(c,subject,OBJ_LIST)) return;
|
||||
|
||||
if (refval != NULL) {
|
||||
/* Seek refval from head to tail */
|
||||
/* Seek pivot from head to tail */
|
||||
iter = listTypeInitIterator(subject,0,LIST_TAIL);
|
||||
while (listTypeNext(iter,&entry)) {
|
||||
if (listTypeEqual(&entry,refval)) {
|
||||
listTypeInsert(&entry,val,where);
|
||||
if (listTypeEqual(&entry,c->argv[3])) {
|
||||
listTypeInsert(&entry,c->argv[4],where);
|
||||
inserted = 1;
|
||||
break;
|
||||
}
|
||||
@ -263,39 +297,10 @@ void pushxGenericCommand(client *c, robj *refval, robj *val, int where) {
|
||||
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));
|
||||
}
|
||||
|
||||
void lpushxCommand(client *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
pushxGenericCommand(c,NULL,c->argv[2],LIST_HEAD);
|
||||
}
|
||||
|
||||
void rpushxCommand(client *c) {
|
||||
c->argv[2] = tryObjectEncoding(c->argv[2]);
|
||||
pushxGenericCommand(c,NULL,c->argv[2],LIST_TAIL);
|
||||
}
|
||||
|
||||
void linsertCommand(client *c) {
|
||||
c->argv[4] = tryObjectEncoding(c->argv[4]);
|
||||
if (strcasecmp(c->argv[2]->ptr,"after") == 0) {
|
||||
pushxGenericCommand(c,c->argv[3],c->argv[4],LIST_TAIL);
|
||||
} else if (strcasecmp(c->argv[2]->ptr,"before") == 0) {
|
||||
pushxGenericCommand(c,c->argv[3],c->argv[4],LIST_HEAD);
|
||||
} else {
|
||||
addReply(c,shared.syntaxerr);
|
||||
}
|
||||
}
|
||||
|
||||
void llenCommand(client *c) {
|
||||
robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.czero);
|
||||
if (o == NULL || checkType(c,o,OBJ_LIST)) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user