mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 08:30:51 +00:00
make LINSERT return -1 when the value could not be inserted
This commit is contained in:
parent
70b4b320ae
commit
23d3a5feef
7
redis.c
7
redis.c
@ -538,7 +538,7 @@ typedef struct zset {
|
||||
|
||||
#define REDIS_SHARED_INTEGERS 10000
|
||||
struct sharedObjectsStruct {
|
||||
robj *crlf, *ok, *err, *emptybulk, *czero, *cone, *pong, *space,
|
||||
robj *crlf, *ok, *err, *emptybulk, *czero, *cone, *cnegone, *pong, *space,
|
||||
*colon, *nullbulk, *nullmultibulk, *queued,
|
||||
*emptymultibulk, *wrongtypeerr, *nokeyerr, *syntaxerr, *sameobjecterr,
|
||||
*outofrangeerr, *plus,
|
||||
@ -1677,6 +1677,7 @@ static void createSharedObjects(void) {
|
||||
shared.emptybulk = createObject(REDIS_STRING,sdsnew("$0\r\n\r\n"));
|
||||
shared.czero = createObject(REDIS_STRING,sdsnew(":0\r\n"));
|
||||
shared.cone = createObject(REDIS_STRING,sdsnew(":1\r\n"));
|
||||
shared.cnegone = createObject(REDIS_STRING,sdsnew(":-1\r\n"));
|
||||
shared.nullbulk = createObject(REDIS_STRING,sdsnew("$-1\r\n"));
|
||||
shared.nullmultibulk = createObject(REDIS_STRING,sdsnew("*-1\r\n"));
|
||||
shared.emptymultibulk = createObject(REDIS_STRING,sdsnew("*0\r\n"));
|
||||
@ -5252,6 +5253,10 @@ static void pushxGenericCommand(redisClient *c, robj *refval, robj *val, int whe
|
||||
ziplistLen(subject->ptr) > server.list_max_ziplist_entries)
|
||||
listTypeConvert(subject,REDIS_ENCODING_LIST);
|
||||
server.dirty++;
|
||||
} else {
|
||||
/* Notify client of a failed insert */
|
||||
addReply(c,shared.cnegone);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
listTypePush(subject,val,where);
|
||||
|
@ -101,10 +101,10 @@ start_server {
|
||||
assert_equal 6 [r linsert xlist after c yy]
|
||||
assert_equal {a b zz c yy d} [r lrange xlist 0 10]
|
||||
assert_equal 7 [r linsert xlist after d dd]
|
||||
assert_equal 7 [r linsert xlist after bad ddd]
|
||||
assert_equal -1 [r linsert xlist after bad ddd]
|
||||
assert_equal {a b zz c yy d dd} [r lrange xlist 0 10]
|
||||
assert_equal 8 [r linsert xlist before a aa]
|
||||
assert_equal 8 [r linsert xlist before bad aaa]
|
||||
assert_equal -1 [r linsert xlist before bad aaa]
|
||||
assert_equal {aa a b zz c yy d dd} [r lrange xlist 0 10]
|
||||
|
||||
# check inserting integer encoded value
|
||||
@ -154,10 +154,10 @@ start_server {
|
||||
|
||||
# don't convert when the value could not be inserted
|
||||
create_ziplist xlist [lrepeat 256 a]
|
||||
assert_equal 256 [r linsert xlist before foo a]
|
||||
assert_equal -1 [r linsert xlist before foo a]
|
||||
assert_encoding ziplist xlist
|
||||
create_ziplist xlist [lrepeat 256 a]
|
||||
assert_equal 256 [r linsert xlist after foo a]
|
||||
assert_equal -1 [r linsert xlist after foo a]
|
||||
assert_encoding ziplist xlist
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user